8152951: Avoid calculating the reverse of StringConcatFactory$Recipe elements

Reviewed-by: shade, vlivanov
This commit is contained in:
Claes Redestad 2016-03-29 18:27:33 +02:00
parent b09c81ce39
commit 3312808cdb

View File

@ -255,7 +255,6 @@ public final class StringConcatFactory {
*/
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 @@ public final class StringConcatFactory {
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 @@ public final class StringConcatFactory {
// 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: {