on master help sign in
Fix getSlot: mixed up search direction if bit magic failed
commit481a7301ee66c9f016a8f8a2b1c7c2eac1d8121e authorChristian Widera <xash@posteo.de> dateFri 8 Aug 2014, 18:01 (12 years ago) parentaebe55e
1 file changed+3−5
libraries/Native/Array.js+3−5
libraries/Native/Array.js+3−5
@@ -35,10 +35,8 @@ Elm.Native.Array.make = function(elm) {
3535 function unsafeGet(i, array) {
3636 for (var x = array.height; x > 0; x--) {
3737 var slot = i >> (x * 5);
38− if (slot > 0) {
39− while (array.lengths[slot - 1] > i) { slot--; }
40− i -= array.lengths[slot - 1];
41− }
38+ while (array.lengths[slot] <= i) slot++;
39+ if (slot > 0) i -= array.lengths[slot - 1];
4240 array = array.table[slot];
4341 }
4442 return array.table[i];
@@ -558,7 +556,7 @@ Elm.Native.Array.make = function(elm) {
558556 // find the exact slot via forward searching in "lengths". Returns the index.
559557 function getSlot(i, a) {
560558 var slot = i >> (5 * a.height);
561− while (a.lengths[slot - 1] > i) { slot--; }
559+ while (a.lengths[slot] <= i) slot++;
562560 return slot;
563561 }
564562