@@ -34,20 +34,15 @@ Elm.Native.Array.make = function(elm) {
3434 }
3535
3636 function unsafeGet(i, array) {
37− var slotSize = Math.pow(M, array.height);
38−
39− while (true) {
40− var slot = Math.floor(i / slotSize);
37+ for (var x = array.height; x > 0; x--) {
38+ var slot = Math.floor(i / cache[x]);
4139 while (array.lengths[slot] <= i) {
4240 slot++;
4341 }
4442 i -= slot > 0 ? array.lengths[slot - 1] : 0;
4543 array = array.table[slot];
46− if (array.height == 0) {
47− return array.table[i];
48− }
49− slotSize /= M;
5044 }
45+ return array.table[i];
5146 }
5247
5348 // Sets the value at the index i. Only the nodes leading to i will get
@@ -537,10 +532,16 @@ Elm.Native.Array.make = function(elm) {
537532 }
538533 }
539534
535+ // Cache for Math.pow(M, i)
536+ cache = new Array(10);
537+ for (var i = 0; i < cache.length; i++) {
538+ cache[i] = Math.pow(M, i);
539+ }
540+
540541 // Calculates in which slot of "table" the item probably is, then
541542 // find the exact slot via forward searching in "lengths". Returns the index.
542543 function getSlot(i, a) {
543− var slot = Math.floor(i / (Math.pow(M, a.height)));
544+ var slot = Math.floor(i / cache[a.height]);
544545 while (a.lengths[slot] <= i) {
545546 slot++
546547 }