@@ -25,18 +25,21 @@ Elm.Native.Array.make = function(elm) {
25 var empty = { ctor:"_Array", height:0, table:new Array() };
25 var empty = { ctor:"_Array", height:0, table:new Array() };
27 // Gets the value at index i recursively.
27 // Gets the value at index i recursively.
28− function get(i, a) {
28+ function get(i, array) {
30− if (i < a.table.length) {
29+ if (i < 0 || i >= length(array)) {
33− throw new Error("Index "+ i +" is out of range. Check the length of your array first or use getSafe or getMaybe.");
30+ throw new Error("Index " + i + " is out of range. Check the length of " +
31+ "your array first or use getMaybe or getWithDefault.");
33+ return unsafeGet(i, array);
36+ function unsafeGet(i, array) {
37+ if (array.height == 0) {
38+ return array.table[i];
37− var slot = getSlot(i, a);
40+ var slot = getSlot(i, array);
38− var sub = slot > 0 ? a.lengths[slot-1] : 0;
41+ var offset = slot > 0 ? array.lengths[slot-1] : 0;
39− return get(i - sub, a.table[slot]);
42+ return unsafeGet(i - offset, array.table[slot]);
42 // Sets the value at the index i. Only the nodes leading to i will get
45 // 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) {
65 return pushed;
68 return pushed;
68− newTree = create(item, a.height);
71+ var newTree = create(item, a.height);
69 return siblise(a, newTree);
72 return siblise(a, newTree);
@@ -423,11 +426,11 @@ Elm.Native.Array.make = function(elm) {
425 // Returns how many items are in the tree.
428 // Returns how many items are in the tree.
426− function length(a) {
429+ function length(array) {
427− if (a.height == 0) {
430+ if (array.height == 0) {
428− return a.table.length;
431+ return array.table.length;
430− return a.lengths[a.lengths.length - 1];
433+ return array.lengths[array.lengths.length - 1];