Commit 5c39aa09 authored by Almar Klein's avatar Almar Klein

Fix for utf-decoding large strings

parent e69feaf4
Pipeline #58573945 (#162) passed with stages
in 6 minutes and 29 seconds
......@@ -52,7 +52,7 @@
"use strict";
var VERSION;
VERSION = [2, 2, 1];
VERSION = [2, 2, 2];
// http://github.com/msgpack/msgpack-javascript/blob/master/msgpack.js#L181-L192
function utf8encode(mix) {
......@@ -85,7 +85,9 @@ function utf8decode(buf) {
((c & 0x0f) << 12 | (buf[++i] & 0x3f) << 6
| (buf[++i] & 0x3f)));
}
return String.fromCharCode.apply(null, ary);
// First line can cause Maximum call stack size exceeded"
// return String.fromCharCode.apply(null, ary);
return ary.map(function(i) {return String.fromCharCode(i)}).join("");
}
......
......@@ -3,11 +3,11 @@
<head><meta charset="utf-8"><title>Test BSDF performance in browser</title></head>
<body>
<script src='../data/rand01.js'></script>
<script src='../data/rand02.js'></script>
<script src='../data/rand03.js'></script>
<script src='../data/rand04_nulldict.js'></script>
<script src='../data/rand05_nulllist.js'></script>
<script src='../_data/rand01.js'></script>
<script src='../_data/rand02.js'></script>
<script src='../_data/rand03.js'></script>
<script src='../_data/rand04_nulldict.js'></script>
<script src='../_data/rand05_nulllist.js'></script>
<script src='bsdf.js'></script>
......@@ -65,7 +65,7 @@ function main() {
t1 = 1000 * (perf_counter() - t0);
t0 = perf_counter();
for (var i=0; i<n; i++) { r2 = bsdf_encode(d); }
for (var i=0; i<n; i++) { r2 = bsdf.encode(d); }
t2 = 1000 * (perf_counter() - t0);
r = Math.round;
......@@ -76,7 +76,7 @@ function main() {
t1 = 1000 * (perf_counter() - t0);
t0 = perf_counter();
for (var i=0; i<n; i++) { d2 = bsdf_decode(r2); }
for (var i=0; i<n; i++) { d2 = bsdf.decode(r2); }
t2 = 1000 * (perf_counter() - t0);
write('decoding: ' + r(t1) + ', ' + r(t2) + ': ' + r(100 * t1/t2) + '%')
......
......@@ -3,14 +3,14 @@
//<script src='../data/data03.js'></script>
bsdf = require('./bsdf.js');
bsdf_encode = bsdf.bsdf_encode;
bsdf_decode = bsdf.bsdf_decode;
rand01 = require('../data/rand01.json');
rand02 = require('../data/rand02.json');
rand03 = require('../data/rand03.json');
rand04_nulldict = require('../data/rand04_nulldict.json');
rand05_nulllist = require('../data/rand05_nulllist.json');
bsdf_encode = bsdf.encode;
bsdf_decode = bsdf.decode;
rand01 = require('../_data/rand01.json');
rand02 = require('../_data/rand02.json');
rand03 = require('../_data/rand03.json');
rand04_nulldict = require('../_data/rand04_nulldict.json');
rand05_nulllist = require('../_data/rand05_nulllist.json');
// ========== functions we need here
......
......@@ -25,6 +25,7 @@ if (fname2.endsWith('.json')) {
fs.writeFileSync(fname2, text, 'utf-8');
} else if (fname2.endsWith('.bsdf')) {
bb = bsdf.encode(data);
// New Node: fs.writeFileSync(fname2, new Buffer.from(bb), {encoding: null});
fs.writeFileSync(fname2, new Buffer(bb), {encoding: null});
} else {
throw "Unexpected file extension for " + fname2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment