@@ -34,20 +34,15 @@ Elm.Native.Array.make = function(elm) {
36 function unsafeGet(i, array) {
36 function unsafeGet(i, array) {
37− var slotSize = Math.pow(M, array.height);
37+ for (var x = array.height; x > 0; x--) {
40− var slot = Math.floor(i / slotSize);
38+ var slot = Math.floor(i / cache[x]);
41 while (array.lengths[slot] <= i) {
39 while (array.lengths[slot] <= i) {
44 i -= slot > 0 ? array.lengths[slot - 1] : 0;
42 i -= slot > 0 ? array.lengths[slot - 1] : 0;
45 array = array.table[slot];
43 array = array.table[slot];
46− if (array.height == 0) {
47− return array.table[i];
45+ return array.table[i];
53 // Sets the value at the index i. Only the nodes leading to i will get
48 // 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) {
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);
540 // Calculates in which slot of "table" the item probably is, then
541 // Calculates in which slot of "table" the item probably is, then
541 // find the exact slot via forward searching in "lengths". Returns the index.
542 // find the exact slot via forward searching in "lengths". Returns the index.
542 function getSlot(i, a) {
543 function getSlot(i, a) {
543− var slot = Math.floor(i / (Math.pow(M, a.height)));
544+ var slot = Math.floor(i / cache[a.height]);
544 while (a.lengths[slot] <= i) {
545 while (a.lengths[slot] <= i) {