Skip to content

Commit 150ab84

Browse files
Code review and clean up for indyfied string concatenation (#4213)
1 parent 71d8c9e commit 150ab84

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/BinaryExpression.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,18 +1564,18 @@ public void generateOptimizedLogicalXor(BlockScope currentScope, CodeStream code
15641564
codeStream.recordPositionsFrom(codeStream.position, this.sourceEnd);
15651565
}
15661566
@Override
1567-
public void buildStringForConcatation(BlockScope blockScope, CodeStream codeStream, int typeID, StringBuilder recipe, List<TypeBinding> argTypes) {
1567+
public void buildStringForConcatenation(BlockScope blockScope, CodeStream codeStream, int typeID, StringBuilder recipe, List<TypeBinding> argTypes) {
15681568
if ((((this.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT) == OperatorIds.PLUS)
15691569
&& ((this.bits & ASTNode.ReturnTypeIDMASK) == TypeIds.T_JavaLangString)) {
15701570
if (this.constant != Constant.NotAConstant) {
1571-
super.buildStringForConcatation(blockScope, codeStream, typeID, recipe, argTypes);
1571+
super.buildStringForConcatenation(blockScope, codeStream, typeID, recipe, argTypes);
15721572
} else {
1573-
this.left.buildStringForConcatation(blockScope, codeStream, this.left.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
1574-
this.right.buildStringForConcatation(blockScope, codeStream, this.right.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
1573+
this.left.buildStringForConcatenation(blockScope, codeStream, this.left.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
1574+
this.right.buildStringForConcatenation(blockScope, codeStream, this.right.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
15751575
}
1576-
} else {
1577-
super.buildStringForConcatation(blockScope, codeStream, typeID, recipe, argTypes);
1578-
}
1576+
} else {
1577+
super.buildStringForConcatenation(blockScope, codeStream, typeID, recipe, argTypes);
1578+
}
15791579
}
15801580
@Override
15811581
public void generateOptimizedStringConcatenation(BlockScope blockScope, CodeStream codeStream, int typeID) {

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CombinedBinaryExpression.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ public void generateOptimizedStringConcatenation(BlockScope blockScope,
238238
}
239239

240240
@Override
241-
public void buildStringForConcatation(BlockScope blockScope, CodeStream codeStream, int typeID, StringBuilder recipe, List<TypeBinding> argTypes) {
241+
public void buildStringForConcatenation(BlockScope blockScope, CodeStream codeStream, int typeID, StringBuilder recipe, List<TypeBinding> argTypes) {
242242
if (this.referencesTable == null) {
243-
super.buildStringForConcatation(blockScope, codeStream, typeID, recipe, argTypes);
243+
super.buildStringForConcatenation(blockScope, codeStream, typeID, recipe, argTypes);
244244
} else {
245245
// copied from below method generateOptimizedStringConcatenationCreation(BlockScope, CodeStream, int)
246246
if ((((this.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT) ==
@@ -257,27 +257,27 @@ public void buildStringForConcatation(BlockScope blockScope, CodeStream codeStre
257257
((cursor.bits & ASTNode.ReturnTypeIDMASK) ==
258258
TypeIds.T_JavaLangString)) {
259259
if (cursor.constant != Constant.NotAConstant) {
260-
cursor.buildStringForConcatation(blockScope, codeStream, typeID, recipe, argTypes);
260+
cursor.buildStringForConcatenation(blockScope, codeStream, typeID, recipe, argTypes);
261261
break;
262262
}
263263
} else {
264-
cursor.buildStringForConcatation(blockScope, codeStream, cursor.implicitConversion &
264+
cursor.buildStringForConcatenation(blockScope, codeStream, cursor.implicitConversion &
265265
TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
266266
break;
267267
}
268268
}
269269
restart++;
270270
if (restart == 0) { // reached the leftmost expression
271-
cursor.left.buildStringForConcatation(blockScope, codeStream, cursor.left.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
271+
cursor.left.buildStringForConcatenation(blockScope, codeStream, cursor.left.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
272272
}
273273
for (int i = restart; i < this.arity; i++) {
274274
cursor = this.referencesTable[i];
275-
cursor.right.buildStringForConcatation(blockScope, codeStream, cursor.right.implicitConversion &
275+
cursor.right.buildStringForConcatenation(blockScope, codeStream, cursor.right.implicitConversion &
276276
TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
277277
}
278-
this.right.buildStringForConcatation(blockScope, codeStream, this.right.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
278+
this.right.buildStringForConcatenation(blockScope, codeStream, this.right.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, argTypes);
279279
} else {
280-
super.buildStringForConcatation(blockScope, codeStream, typeID, recipe, argTypes);
280+
super.buildStringForConcatenation(blockScope, codeStream, typeID, recipe, argTypes);
281281
}
282282
}
283283
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/Expression.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -843,22 +843,20 @@ public void generateOptimizedStringConcatenationCreation(BlockScope blockScope,
843843
codeStream.invokeStringConcatenationStringConstructor();
844844
}
845845
private void addArgumentToRecipe(BlockScope blockScope, CodeStream codeStream, StringBuilder recipe, TypeBinding argType, List<TypeBinding> args) {
846-
recipe.append(STRING_CONCAT_MARKER_1);
846+
recipe.append(STRING_CONCAT_FACTORY_TAG_ARG);
847847
args.add(argType);
848848
if (args.size() > 190) {
849-
// StringConcatFactory#makeConcatWithConstants() can take only 200 arguments
850-
// Commit whatever we have accumulated so far
851-
// Get the result pushed to the stack and to be used as an operand
852-
// for the subsequent concat operation
849+
// StringConcatFactory#makeConcatWithConstants() can take only 200 arguments. Commit whatever we have accumulated so far
850+
// Get the intermediate result pushed to the stack and to be used as an operand for the subsequent concat operation
853851
codeStream.invokeDynamicForStringConcat(recipe, args);
854852
// Clear the arguments for the next batch
855853
args.clear();
856854
recipe.delete(0, recipe.length());
857-
recipe.append(TypeConstants.STRING_CONCAT_MARKER_1);
855+
recipe.append(TypeConstants.STRING_CONCAT_FACTORY_TAG_ARG);
858856
args.add(blockScope.getJavaLangString());
859857
}
860858
}
861-
public void buildStringForConcatation(BlockScope blockScope, CodeStream codeStream, int typeID, StringBuilder recipe, List<TypeBinding> argTypes) {
859+
public void buildStringForConcatenation(BlockScope blockScope, CodeStream codeStream, int typeID, StringBuilder recipe, List<TypeBinding> argTypes) {
862860
if (this.constant == Constant.NotAConstant) {
863861
switch (typeID) {
864862
case T_JavaLangString :
@@ -885,11 +883,12 @@ public void buildStringForConcatation(BlockScope blockScope, CodeStream codeStre
885883
}
886884
} else {
887885
// StringLiteral and CharLiteral may contain special characters
888-
if (this.constant.stringValue().indexOf('\u0001') != -1 || this.constant.stringValue().indexOf('\u0002') != -1) {
889-
codeStream.ldc(this.constant.stringValue());
886+
final String stringValue = this.constant.stringValue();
887+
if (stringValue.indexOf(TypeConstants.STRING_CONCAT_FACTORY_TAG_ARG) != -1 || stringValue.indexOf(TypeConstants.STRING_CONCAT_FACTORY_TAG_CONST) != -1) {
888+
codeStream.ldc(stringValue);
890889
addArgumentToRecipe(blockScope, codeStream, recipe, blockScope.getJavaLangString(), argTypes);
891890
} else {
892-
recipe.append(this.constant.stringValue());
891+
recipe.append(stringValue);
893892
}
894893
}
895894
}

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,11 +2340,11 @@ public void generateStringConcatenationAppend(BlockScope blockScope, Expression
23402340
// Operand is already on the stack
23412341
invokeStringValueOf(TypeIds.T_JavaLangObject);
23422342
arguments.add(blockScope.getJavaLangString());
2343-
recipe.append(TypeConstants.STRING_CONCAT_MARKER_1);
2343+
recipe.append(TypeConstants.STRING_CONCAT_FACTORY_TAG_ARG);
23442344
} else {
2345-
oper1.buildStringForConcatation(blockScope, this, oper1.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, arguments);
2345+
oper1.buildStringForConcatenation(blockScope, this, oper1.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, arguments);
23462346
}
2347-
oper2.buildStringForConcatation(blockScope, this, oper2.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, arguments);
2347+
oper2.buildStringForConcatenation(blockScope, this, oper2.implicitConversion & TypeIds.COMPILE_TYPE_MASK, recipe, arguments);
23482348
invokeDynamicForStringConcat(recipe, arguments);
23492349
} else {
23502350
int pc;

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ public interface TypeConstants {
119119
char[] UPPER_MODULE = "MODULE".toCharArray(); //$NON-NLS-1$
120120
char[] UPPER_RECORD_COMPONENT = "RECORD_COMPONENT".toCharArray(); //$NON-NLS-1$
121121
char[] YIELD = "yield".toCharArray(); //$NON-NLS-1$
122-
// Duplicated since java.lang.invoke.StringConcatFactory.TAG_ARG isn't public
123-
char[] STRING_CONCAT_MARKER_1 = new char[] {'\u0001'};
122+
// Duplicated since java.lang.invoke.StringConcatFactory.TAG_{ARG|CONST} isn't public
123+
char STRING_CONCAT_FACTORY_TAG_ARG = '\u0001';
124+
char STRING_CONCAT_FACTORY_TAG_CONST = '\u0002';
124125

125126
// JEP 286
126127
char[] VAR = "var".toCharArray(); //$NON-NLS-1$

0 commit comments

Comments
 (0)