X-Git-Url: http://git.megacz.com/?p=org.ibex.js.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fjs%2FJSArray.java;h=52c1878ce670a18beb70b810fce9f9ad4e45898f;hp=7b90de74ee9e78468a5f40cc461bf653baef8598;hb=e43daa0ce0ebd7cf6045430ed62a2562c0502c23;hpb=b1fa73c17b31f268fca5695d0876d7314fbacce3 diff --git a/src/org/ibex/js/JSArray.java b/src/org/ibex/js/JSArray.java index 7b90de7..52c1878 100644 --- a/src/org/ibex/js/JSArray.java +++ b/src/org/ibex/js/JSArray.java @@ -7,6 +7,8 @@ import java.util.*; /** A JavaScript JSArray */ public class JSArray extends JS { private static final Object NULL = new Object(); + + private BalancedTree arr = new BalancedTree(); public JSArray() { } public JSArray(int size) { setSize(size); } @@ -118,27 +120,27 @@ public class JSArray extends JS { public final int length() { return size(); } public final Object elementAt(int i) { if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i); - Object o = getNode(i); + Object o = arr.getNode(i); return o == NULL ? null : o; } public final void addElement(Object o) { - insertNode(size(),o==null ? NULL : o); + arr.insertNode(size(),o==null ? NULL : o); } public final void setElementAt(Object o, int i) { if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i); - replaceNode(i,o==null ? NULL : o); + arr.replaceNode(i,o==null ? NULL : o); } public final void insertElementAt(Object o, int i) { if(i < 0 || i > size()) throw new ArrayIndexOutOfBoundsException(i); - insertNode(i,o==null ? NULL : o); + arr.insertNode(i,o==null ? NULL : o); } public final Object removeElementAt(int i) { if(i < 0 || i >= size()) throw new ArrayIndexOutOfBoundsException(i); - Object o = deleteNode(i); + Object o = arr.deleteNode(i); return o == NULL ? null : o; } - public final int size() { return treeSize(); } + public final int size() { return arr.treeSize(); } public String typeName() { return "array"; } private Object join(String sep) { @@ -160,7 +162,7 @@ public class JSArray extends JS { int size = size(); if(size < 2) return this; Vec vec = toVec(); - clear(); + arr.clear(); for(int i=size-1,j=0;i>=0;i--,j++) insertElementAt(vec.elementAt(i),j); return this; } @@ -238,12 +240,12 @@ public class JSArray extends JS { return ret; } - protected Vec toVec() { + public Vec toVec() { int count = size(); Vec vec = new Vec(); vec.setSize(count); for(int i=0;i