checkpoint
[sbp.git] / src / edu / berkeley / sbp / GSS.java
index abe4aa3..6db929b 100644 (file)
@@ -27,6 +27,8 @@ class GSS {
 
     public GSS() { }
 
+    private Phase.Node[] reducing_list = null;
+
     /** corresponds to a positions <i>between tokens</i> the input stream; same as Tomita's U_i's */
     public class Phase {
 
@@ -107,10 +109,17 @@ class GSS {
         /** perform all reduction operations */
         public void reduce() {
             reducing = true;
-            HashSet<Phase.Node> s = new HashSet<Phase.Node>();
-            s.addAll(hash.values());
-            for(Phase.Node n : s) n.queueEmptyReductions();
-            for(Phase.Node n : s) n.queueReductions();
+            if (reducing_list==null || reducing_list.length < hash.size())
+                reducing_list = new Phase.Node[hash.size() * 4];
+            Collection<Node> hv = hash.values();
+            hv.toArray(reducing_list);
+            int num = hv.size();
+            for(int i=0; i<num; i++) {
+                Node n = reducing_list[i];
+                reducing_list[i] = null;
+                n.queueEmptyReductions();
+                n.queueReductions();
+            }
         }
 
         /** perform all shift operations, adding promoted nodes to <tt>next</tt> */