changeset 13971:841f1fe6d486

8152951: Avoid calculating the reverse of StringConcatFactory$Recipe elements Reviewed-by: shade, vlivanov
author redestad
date Tue, 29 Mar 2016 18:27:33 +0200
parents 271faffbe204
children fa4686fe4fac
files src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java
diffstat 1 files changed, 5 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java	Tue Mar 29 18:04:41 2016 +0900
+++ b/src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java	Tue Mar 29 18:27:33 2016 +0200
@@ -255,7 +255,6 @@
      */
     private static final class Recipe {
         private final List<RecipeElement> elements;
-        private final List<RecipeElement> elementsRev;
 
         public Recipe(String src, Object[] constants) {
             List<RecipeElement> el = new ArrayList<>();
@@ -294,19 +293,13 @@
                 el.add(new RecipeElement(acc.toString()));
             }
 
-            elements = new ArrayList<>(el);
-            Collections.reverse(el);
-            elementsRev = el;
+            elements = el;
         }
 
-        public Collection<RecipeElement> getElements() {
+        public List<RecipeElement> getElements() {
             return elements;
         }
 
-        public Collection<RecipeElement> getElementsReversed() {
-            return elementsRev;
-        }
-
         @Override
         public boolean equals(Object o) {
             if (this == o) return true;
@@ -1310,7 +1303,9 @@
 
             // Compose append calls. This is done in reverse because the application order is
             // reverse as well.
-            for (RecipeElement el : recipe.getElementsReversed()) {
+            List<RecipeElement> elements = recipe.getElements();
+            for (int i = elements.size() - 1; i >= 0; i--) {
+                RecipeElement el = elements.get(i);
                 MethodHandle appender;
                 switch (el.getTag()) {
                     case CONST: {