changeset 17969:0a4ddfce5b84

8015674: CodeGenerator.initSymbols mutates a list Reviewed-by: jlaskey, lagergren
author attila
date Fri, 31 May 2013 12:57:44 +0200
parents 108ba976aa02
children a85557027014
files nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java
diffstat 1 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Fri May 31 12:57:25 2013 +0200
+++ b/nashorn/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Fri May 31 12:57:44 2013 +0200
@@ -456,17 +456,18 @@
     }
 
     private void initSymbols(final LinkedList<Symbol> symbols, final Type type) {
-        if (symbols.isEmpty()) {
-            return;
-        }
-
-        method.loadUndefined(type);
-        while (!symbols.isEmpty()) {
-            final Symbol symbol = symbols.removeFirst();
-            if (!symbols.isEmpty()) {
-                method.dup();
-            }
-            method.store(symbol);
+        final Iterator<Symbol> it = symbols.iterator();
+        if(it.hasNext()) {
+            method.loadUndefined(type);
+            boolean hasNext;
+            do {
+                final Symbol symbol = it.next();
+                hasNext = it.hasNext();
+                if(hasNext) {
+                    method.dup();
+                }
+                method.store(symbol);
+            } while(hasNext);
         }
     }