@@ -35,8 +35,10 @@ Elm.Native.Array.make = function(elm) {
35 function unsafeGet(i, array) {
35 function unsafeGet(i, array) {
36 for (var x = array.height; x > 0; x--) {
36 for (var x = array.height; x > 0; x--) {
37 var slot = i >> (x * 5);
37 var slot = i >> (x * 5);
38+ while (array.lengths[slot] <= i) {
38 if (slot > 0) {
41 if (slot > 0) {
39− while (array.lengths[slot - 1] > i) { slot--; }
40 i -= array.lengths[slot - 1];
42 i -= array.lengths[slot - 1];
42 array = array.table[slot];
44 array = array.table[slot];
@@ -311,10 +313,12 @@ Elm.Native.Array.make = function(elm) {
312 // Create new node.
314 // Create new node.
313 var newA = { ctor:"_Array", height:a.height
315 var newA = { ctor:"_Array", height:a.height
314− , table:a.table.slice(0, right + 1)
316+ , table:a.table.slice(0, right)
315− , lengths:a.lengths.slice(0, right + 1) };
317+ , lengths:a.lengths.slice(0, right) };
318+ if (sliced.table.length > 0) {
316− newA.table[right] = sliced;
319+ newA.table[right] = sliced;
317− newA.lengths[right] = length(sliced) + (right > 0 ? newA.lengths[right - 1] : 0);
320+ newA.lengths[right] = length(sliced) + (right > 0 ? newA.lengths[right - 1] : 0);
318 return newA;
322 return newA;
@@ -343,7 +347,7 @@ Elm.Native.Array.make = function(elm) {
343 var newA = { ctor:"_Array", height:a.height
347 var newA = { ctor:"_Array", height:a.height
344 , table:a.table.slice(left, a.table.length + 1)
348 , table:a.table.slice(left, a.table.length + 1)
345 , lengths:new Array(a.table.length - left) };
349 , lengths:new Array(a.table.length - left) };
346− newA.table[left] = sliced;
350+ newA.table[0] = sliced;
347 var len = 0;
351 var len = 0;
348 for (var i = 0; i < newA.table.length; i++) {
352 for (var i = 0; i < newA.table.length; i++) {
349 len += length(newA.table[i]);
353 len += length(newA.table[i]);
@@ -558,7 +562,9 @@ Elm.Native.Array.make = function(elm) {
558 // find the exact slot via forward searching in "lengths". Returns the index.
562 // find the exact slot via forward searching in "lengths". Returns the index.
559 function getSlot(i, a) {
563 function getSlot(i, a) {
560 var slot = i >> (5 * a.height);
564 var slot = i >> (5 * a.height);
561− while (a.lengths[slot - 1] > i) { slot--; }
565+ while (a.lengths[slot] <= i) {
562 return slot;
568 return slot;