< prev index next >
src/java.base/share/classes/java/lang/invoke/StringConcatFactory.java
Print this page
rev 13970 : 8152951: Avoid calculating the reverse of StringConcatFactory$Recipe elements
Reviewed-by: shade
*** 253,263 ****
* strategies. Notably, this class parses out the constants from the recipe
* and from other static arguments.
*/
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<>();
int constC = 0;
--- 253,262 ----
*** 292,314 ****
// Flush the remaining characters as constant:
if (acc.length() > 0) {
el.add(new RecipeElement(acc.toString()));
}
! elements = new ArrayList<>(el);
! Collections.reverse(el);
! elementsRev = el;
}
! public Collection<RecipeElement> getElements() {
return elements;
}
- public Collection<RecipeElement> getElementsReversed() {
- return elementsRev;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
--- 291,307 ----
// Flush the remaining characters as constant:
if (acc.length() > 0) {
el.add(new RecipeElement(acc.toString()));
}
! elements = el;
}
! public List<RecipeElement> getElements() {
return elements;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
*** 1308,1318 ****
// Create (StringBuilder, <args>) shape for appending:
MethodHandle builder = MethodHandles.dropArguments(MethodHandles.identity(StringBuilder.class), 1, ptypesList);
// Compose append calls. This is done in reverse because the application order is
// reverse as well.
! for (RecipeElement el : recipe.getElementsReversed()) {
MethodHandle appender;
switch (el.getTag()) {
case CONST: {
Object constant = el.getValue();
MethodHandle mh = appender(adaptToStringBuilder(constant.getClass()));
--- 1301,1313 ----
// Create (StringBuilder, <args>) shape for appending:
MethodHandle builder = MethodHandles.dropArguments(MethodHandles.identity(StringBuilder.class), 1, ptypesList);
// Compose append calls. This is done in reverse because the application order is
// reverse as well.
! 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: {
Object constant = el.getValue();
MethodHandle mh = appender(adaptToStringBuilder(constant.getClass()));
< prev index next >