switch core files over to baskets
[org.ibex.js.git] / src / org / ibex / js / JS.java
index 0a3843c..6d17d31 100644 (file)
@@ -165,7 +165,7 @@ public interface JS extends Pausable {
         public String coerceToString() { return clonee.coerceToString(); }
     }
 
-    public static class Obj extends LinearStore implements JS {
+    public static class Obj extends Basket.Hash implements JS {
         private static final String[] emptystr = new String[0];
         private static final Placeholder holder = new Placeholder();
 
@@ -196,9 +196,20 @@ public interface JS extends Pausable {
         public String[] getFormalArgs() { return emptystr; }
 
         public Enumeration keys() throws JSExn {
-            // FEATURE: replicate some code from a superclass to avoid double object creation
-            return new Enumeration.JavaIterator(null, new LinearStore.IndexIterator() {
-                public Object next() { return entries[nextIndex()]; } });
+            return new Enumeration(null) {
+                private int dest = -1, next = -1;
+                public boolean _hasNext() {
+                    for (int i = Math.max(0, dest); i < usedslots; i++)
+                        if (i > 0 ? entries[i * indexmultiple] != null : true &&
+                            entries[i * indexmultiple] != this) { next = i; return true; }
+                    return false;
+                }
+                public JS _next() throws JSExn {
+                    if (next < 0 && !hasNext()) throw new NoSuchElementException();
+                    int index = next; dest = next; next = -1;
+                    return (JS)entries[index * indexmultiple];
+                }
+            };
         }
         public JS get(JS key) throws JSExn { int i = indexOf(key);
             return i < 0 ? null : entries[i + 1] instanceof Placeholder ?  null : (JS)entries[i + 1]; }