aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@mozilla.com>2010-11-26 13:48:46 -0800
committerAlon Zakai <azakai@mozilla.com>2010-11-26 13:48:46 -0800
commit760f8dba70c9a108ff7cacd9950464fde26b54c1 (patch)
tree73c7f63c0b61949248e1eb81b9cb9faabc19ac98
parent749092eb2942001f1fa2f8b6fcdcbce80f1e8e37 (diff)
do not try to unflatten slabs at runtime
-rw-r--r--src/preamble.js48
1 files changed, 7 insertions, 41 deletions
diff --git a/src/preamble.js b/src/preamble.js
index d70ec570..976e3c90 100644
--- a/src/preamble.js
+++ b/src/preamble.js
@@ -109,51 +109,20 @@ function Pointer_make(slab, pos, allocator) {
pos = pos ? pos : 0;
assert(pos === 0); // TODO: remove 'pos'
if (slab === HEAP) return pos;
- var size = 0;
-
- // The slab may contain arrays, which we basically need to 'flatten' out
- // into one long slab. We do that by traversing it, and not by creating
- // a new slab, to save time and memory
- var stack = [[slab, 0]], top, curr;
- while(1) {
- top = stack[stack.length-1];
- if (top[1] >= top[0].length) {
- stack.pop();
- if (stack.length === 0) break;
- top = stack[stack.length-1];
- top[1]++;
- continue;
- }
- var curr = top[0][top[1]];
- if (curr === undefined)
+ var size = slab.length;
+
+ var i;
+ for (i = 0; i < size; i++) {
+ if (slab[i] === undefined) {
throw 'Invalid element in slab'; // This can be caught, and you can try again to allocate later, see globalFuncs in run()
- if (curr.length) {
- stack.push([curr,0]);
- continue;
}
- size++;
- top[1]++;
}
// Finalize
var ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc][allocator ? allocator : ALLOC_STATIC](Math.max(size, 1));
- stack = [[slab, 0]];
- var i = 0;
- while(1) {
- top = stack[stack.length-1];
- if (top[1] >= top[0].length) {
- stack.pop();
- if (stack.length === 0) break;
- top = stack[stack.length-1];
- top[1]++;
- continue;
- }
- var curr = top[0][top[1]];
- if (curr.length) {
- stack.push([curr,0]);
- continue;
- }
+ for (i = 0; i < size; i++) {
+ var curr = slab[i];
if (typeof curr === 'function') {
curr = Runtime.getFunctionIndex(curr);
@@ -173,9 +142,6 @@ function Pointer_make(slab, pos, allocator) {
HEAP[ret + i] = curr;
#endif
#endif
-
- top[1]++;
- i++;
}
return ret;