diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-03 10:15:24 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-03 10:24:23 -0800 |
commit | 01371349a2f9dffb41003ec68ac43220381bba9b (patch) | |
tree | c53e73f2b6cdb65ae56877f8485c903cbd275ae9 /src/preamble.js | |
parent | 485cee0a7ae5a251f8a83bbb3e3b02802a1b4591 (diff) |
optimize allocate()ion of zeroinit
Diffstat (limited to 'src/preamble.js')
-rw-r--r-- | src/preamble.js | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/preamble.js b/src/preamble.js index 8bde7284..9bc68d8f 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -412,14 +412,6 @@ Module['ALLOC_STACK'] = ALLOC_STACK; Module['ALLOC_STATIC'] = ALLOC_STATIC; Module['ALLOC_NONE'] = ALLOC_NONE; -// Simple unoptimized memset - necessary during startup -var _memset = function(ptr, value, num) { - var stop = ptr + num; - while (ptr < stop) { - {{{ makeSetValue('ptr++', 0, 'value', 'i8', null, true) }}}; - } -} - // allocate(): This is for internal use. You can use it yourself as well, but the interface // is a little tricky (see docs right below). The reason is that it is optimized // for multiple syntaxes to save space in generated code. So you should @@ -453,7 +445,18 @@ function allocate(slab, types, allocator, ptr) { } if (zeroinit) { - _memset(ret, 0, size); + var ptr = ret, stop; +#if USE_TYPED_ARRAYS == 2 + assert((ret & 3) == 0); + stop = ret + (size & ~3); + for (; ptr < stop; ptr += 4) { + {{{ makeSetValue('ptr', '0', '0', 'i32', null, true) }}}; + } +#endif + stop = ret + size; + while (ptr < stop) { + {{{ makeSetValue('ptr++', '0', '0', 'i8', null, true) }}}; + } return ret; } |