diff options
author | Lukas Lihotzki <lukas@lihotzki.de> | 2020-10-06 12:02:17 +0200 |
---|---|---|
committer | Lukas Lihotzki <lukas@lihotzki.de> | 2020-10-06 12:02:17 +0200 |
commit | 030e506c00bc3cd59f5e31f9a14a52a63c7c033a (patch) | |
tree | 5cadd6b2314f94671d536d353d18e0c455de5cef | |
parent | 22f85d3f3d5a043c90486992008347ddd97529d9 (diff) |
use stackAlloc instead of allocate
-rw-r--r-- | javascript/olm_post.js | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/javascript/olm_post.js b/javascript/olm_post.js index 82dd803..450861a 100644 --- a/javascript/olm_post.js +++ b/javascript/olm_post.js @@ -2,12 +2,20 @@ var malloc = Module['_malloc']; var free = Module['_free']; var OLM_ERROR; +function filled_stack(size, filler) { + var ptr = stackAlloc(size); + filler(new Uint8Array(Module['HEAPU8'].buffer, ptr, size)); + return ptr; +} + /* allocate a number of bytes of storage on the stack. * * If size_or_array is a Number, allocates that number of zero-initialised bytes. */ function stack(size_or_array) { - return allocate(size_or_array, 'i8', Module['ALLOC_STACK']); + return (typeof size_or_array == 'number') + ? filled_stack(size_or_array, function(x) { x.fill(0) }) + : filled_stack(size_or_array.length, function(x) { x.set(size_or_array) }); } function array_from_string(string) { @@ -15,10 +23,7 @@ function array_from_string(string) { } function random_stack(size) { - var ptr = stack(size); - var array = new Uint8Array(Module['HEAPU8'].buffer, ptr, size); - get_random_values(array); - return ptr; + return filled_stack(size, get_random_values); } function restore_stack(wrapped) { |