Skip to content

Commit

Permalink
Move pool of pre-computed parameter names for additional reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 1, 2018
1 parent 91cfa0d commit 7d81990
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,12 @@ private Parameter[] makeParameters(CompileUnit cu, Type[] types, Class[] cls, An

protected void fillParameterNames(String[] names, Member member) {
for (int i = 0, n = names.length; i < n; i += 1) {
names[i] = "param" + i;
names[i] = (i < ARGS.length ? ARGS[i] : "arg" + i);
}
}

// arbitrary choice of first ten; maintaining this array prevents many thousands of "argN" string/char[] instances
public static final String[] ARGS = {"arg0", "arg1", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7", "arg8", "arg9"};
// GRECLIPSE end

public void invalidateCallSites() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,12 @@ private Parameter[] makeParameters(CompileUnit cu, Type[] types, Class[] cls, An

protected void fillParameterNames(String[] names, Member member) {
for (int i = 0, n = names.length; i < n; i += 1) {
names[i] = "param" + i;
names[i] = (i < ARGS.length ? ARGS[i] : "arg" + i);
}
}

// arbitrary choice of first ten; maintaining this array prevents many thousands of "argN" string/char[] instances
public static final String[] ARGS = {"arg0", "arg1", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7", "arg8", "arg9"};
// GRECLIPSE end

public void invalidateCallSites() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,12 @@ private Parameter[] makeParameters(CompileUnit cu, Type[] types, Class[] cls, An

protected void fillParameterNames(String[] names, Member member) {
for (int i = 0, n = names.length; i < n; i += 1) {
names[i] = "param" + i;
names[i] = (i < ARGS.length ? ARGS[i] : "arg" + i);
}
}

// arbitrary choice of first ten; maintaining this array prevents many thousands of "argN" string/char[] instances
public static final String[] ARGS = {"arg0", "arg1", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7", "arg8", "arg9"};
// GRECLIPSE end

public void invalidateCallSites() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.codehaus.groovy.ast.expr.ConstantExpression;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.vmplugin.v5.Java5;
import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration.FieldDeclarationWithInitializer;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.compiler.CharOperation;
Expand Down Expand Up @@ -81,9 +82,6 @@
*/
public class JDTClassNode extends ClassNode implements JDTNode {

// arbitrary choice of first eight; maintaining these as a constant array prevents 10000 strings called 'arg0' consuming memory
private static final String[] argNames = {"arg0", "arg1", "arg2", "arg3", "arg4", "arg5", "arg6", "arg7"};

private static final ClassNode unboundWildcard; // represents plain old '?'
static {
unboundWildcard = ClassHelper.makeWithoutCaching("?");
Expand Down Expand Up @@ -376,8 +374,8 @@ private Parameter[] makeParameters(TypeBinding[] parameterTypes, char[][] parame
String parameterName;
if (i < parameterNames.length) {
parameterName = String.valueOf(parameterNames[i]);
} else if (i < argNames.length) {
parameterName = argNames[i];
} else if (i < Java5.ARGS.length) {
parameterName = Java5.ARGS[i];
} else {
parameterName = "arg" + i;
}
Expand Down

0 comments on commit 7d81990

Please sign in to comment.