on master help sign in
Split set
commit49b4ca84e9b3372e4e85e8ead48f5479a29512ef authorChristian Widera <xash@posteo.de> dateWed 23 Apr 2014, 12:38 (13 years ago) parentfb59626
1 file changed+8−4
libraries/Native/Array.js+8−4
libraries/Native/Array.js+8−4
@@ -47,10 +47,14 @@ Elm.Native.Array.make = function(elm) {
4747
4848 // Sets the value at the index i. Only the nodes leading to i will get
4949 // copied and updated.
50− function set(i, item, a) {
51− if (length(a) <= i) {
52− return a;
50+ function set(i, item, array) {
51+ if (i < 0 || length(array) <= i) {
52+ return array;
5353 }
54+ return unsafeSet(i, item, array);
55+ }
56+
57+ function unsafeSet(i, item, a) {
5458 var newA = nodeCopy(a);
5559
5660 if (a.height == 0) {
@@ -58,7 +62,7 @@ Elm.Native.Array.make = function(elm) {
5862 } else {
5963 var slot = getSlot(i, a);
6064 var sub = slot > 0 ? a.lengths[slot-1] : 0;
61− newA.table[slot] = set(i - sub, item, a.table[slot]);
65+ newA.table[slot] = unsafeSet(i - sub, item, a.table[slot]);
6266 }
6367 return newA;
6468 }