@@ -25,18 +25,21 @@ Elm.Native.Array.make = function(elm) {
2525 var empty = { ctor:"_Array", height:0, table:new Array() };
2626
2727 // Gets the value at index i recursively.
28− function get(i, a) {
29− if (a.height == 0) {
30− if (i < a.table.length) {
31− return a.table[i];
32− } else {
33− throw new Error("Index "+ i +" is out of range. Check the length of your array first or use getSafe or getMaybe.");
28+ function get(i, array) {
29+ if (i < 0 || i >= length(array)) {
30+ throw new Error("Index " + i + " is out of range. Check the length of " +
31+ "your array first or use getMaybe or getWithDefault.");
3432 }
35− }
33+ return unsafeGet(i, array);
34+ }
3635
37− var slot = getSlot(i, a);
38− var sub = slot > 0 ? a.lengths[slot-1] : 0;
39− return get(i - sub, a.table[slot]);
36+ function unsafeGet(i, array) {
37+ if (array.height == 0) {
38+ return array.table[i];
39+ }
40+ var slot = getSlot(i, array);
41+ var offset = slot > 0 ? array.lengths[slot-1] : 0;
42+ return unsafeGet(i - offset, array.table[slot]);
4043 }
4144
4245 // Sets the value at the index i. Only the nodes leading to i will get
@@ -65,7 +68,7 @@ Elm.Native.Array.make = function(elm) {
6568 return pushed;
6669 }
6770
68− newTree = create(item, a.height);
71+ var newTree = create(item, a.height);
6972 return siblise(a, newTree);
7073 }
7174
@@ -423,11 +426,11 @@ Elm.Native.Array.make = function(elm) {
423426 }
424427
425428 // Returns how many items are in the tree.
426− function length(a) {
427− if (a.height == 0) {
428− return a.table.length;
429+ function length(array) {
430+ if (array.height == 0) {
431+ return array.table.length;
429432 } else {
430− return a.lengths[a.lengths.length - 1];
433+ return array.lengths[array.lengths.length - 1];
431434 }
432435 }
433436