From c49bd0cb2bcec4c75cc1a50de775635e8d33ee66 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 9 Oct 2017 18:02:08 +0900 Subject: [js] use funcions in preamble.js --- docs/demo/bls.js | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'docs/demo') diff --git a/docs/demo/bls.js b/docs/demo/bls.js index 4f6c21b..f4cbb9f 100644 --- a/docs/demo/bls.js +++ b/docs/demo/bls.js @@ -32,10 +32,11 @@ function define_bls_extra_functions(mod) { throw('err gen_str:' + x) } if (doesReturnString) { - let s = '' - for (let i = 0; i < n; i++) { - s += String.fromCharCode(mod.HEAP8[pos + i]) - } +// let s = '' +// for (let i = 0; i < n; i++) { +// s += String.fromCharCode(mod.HEAP8[pos + i]) +// } + let s = mod.Pointer_stringify(pos, n) mod.Runtime.stackRestore(stack) return s } else { @@ -56,13 +57,9 @@ function define_bls_extra_functions(mod) { let stack = mod.Runtime.stackSave() let pos = mod.Runtime.stackAlloc(buf.length) if (typeof(buf) == "string") { - for (let i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf.charCodeAt(i) - } + mod.writeAsciiToMemory(buf, pos) } else { - for (let i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf[i] - } + mod.writeArrayToMemory(pos, buf) } let r = func(pos, buf.length, ioMode) mod.Runtime.stackRestore(stack) @@ -75,13 +72,9 @@ function define_bls_extra_functions(mod) { let stack = mod.Runtime.stackSave() let pos = mod.Runtime.stackAlloc(buf.length) if (typeof(buf) == "string") { - for (let i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf.charCodeAt(i) - } + mod.writeAsciiToMemory(buf, pos) } else { - for (let i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf[i] - } + mod.writeArrayToMemory(pos, buf) } let r = func(x1, pos, buf.length, ioMode) mod.Runtime.stackRestore(stack) @@ -94,13 +87,9 @@ function define_bls_extra_functions(mod) { let stack = mod.Runtime.stackSave() let pos = mod.Runtime.stackAlloc(buf.length) if (typeof(buf) == "string") { - for (let i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf.charCodeAt(i) - } + mod.writeAsciiToMemory(buf, pos) } else { - for (let i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf[i] - } + mod.writeArrayToMemory(pos, buf) } let r = func(x1, x2, pos, buf.length, ioMode) mod.Runtime.stackRestore(stack) -- cgit v1.2.3