diff options
author | Robert Wertman <robert.wertman@gmail.com> | 2019-01-27 00:39:30 -0500 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2019-01-28 20:44:53 +0100 |
commit | f2d03973d59d96d8bfef51d8378a4069d8d46205 (patch) | |
tree | d3d75b5fbca4e64d5ee967f3ec90b547019e89fd /src/core/lombok | |
parent | ccd802503d8aa578be3f1f956d97b06a803de0aa (diff) | |
download | lombok-f2d03973d59d96d8bfef51d8378a4069d8d46205.tar.gz lombok-f2d03973d59d96d8bfef51d8378a4069d8d46205.tar.bz2 lombok-f2d03973d59d96d8bfef51d8378a4069d8d46205.zip |
Replace sized array in toArray with 0
This approach has been benchmarked to be marginally faster.
Fixes #2030.
Diffstat (limited to 'src/core/lombok')
13 files changed, 25 insertions, 25 deletions
diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java index 77443ba1..78761f46 100644..100755 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -229,7 +229,7 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>, List<FieldAccess> fieldList = new ArrayList<FieldAccess>(); getFields(c, fieldList); - fieldsOfASTClasses.putIfAbsent(c, fieldList.toArray(new FieldAccess[fieldList.size()])); + fieldsOfASTClasses.putIfAbsent(c, fieldList.toArray(new FieldAccess[0])); return fieldsOfASTClasses.get(c); } diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java index b9b9e07d..81ddbd0a 100644..100755 --- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java +++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java @@ -341,7 +341,7 @@ public class EclipseSingularsRecipes { } if (arguments.isEmpty()) return null; - return arguments.toArray(new TypeReference[arguments.size()]); + return arguments.toArray(new TypeReference[0]); } private static final char[] SIZE_TEXT = new char[] {'s', 'i', 'z', 'e'}; diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java index fc11aff2..890a04bc 100644..100755 --- a/src/core/lombok/eclipse/handlers/HandleBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java @@ -663,7 +663,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { if (staticName == null) { AllocationExpression allocationStatement = new AllocationExpression(); allocationStatement.type = copyType(out.returnType); - allocationStatement.arguments = args.isEmpty() ? null : args.toArray(new Expression[args.size()]); + allocationStatement.arguments = args.isEmpty() ? null : args.toArray(new Expression[0]); statements.add(new ReturnStatement(allocationStatement, 0, 0)); } else { MessageSend invoke = new MessageSend(); @@ -674,14 +674,14 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> { invoke.receiver = new QualifiedThisReference(new SingleTypeReference(type.up().getName().toCharArray(), 0) , 0, 0); invoke.typeArguments = typeParameterNames(((TypeDeclaration) type.get()).typeParameters); - invoke.arguments = args.isEmpty() ? null : args.toArray(new Expression[args.size()]); + invoke.arguments = args.isEmpty() ? null : args.toArray(new Expression[0]); if (returnType instanceof SingleTypeReference && Arrays.equals(TypeConstants.VOID, ((SingleTypeReference) returnType).token)) { statements.add(invoke); } else { statements.add(new ReturnStatement(invoke, 0, 0)); } } - out.statements = statements.isEmpty() ? null : statements.toArray(new Statement[statements.size()]); + out.statements = statements.isEmpty() ? null : statements.toArray(new Statement[0]); out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return out; } diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java index 82859e4b..660b9985 100644..100755 --- a/src/core/lombok/eclipse/handlers/HandleConstructor.java +++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java @@ -447,8 +447,8 @@ public class HandleConstructor { } nullChecks.addAll(assigns); - constructor.statements = nullChecks.isEmpty() ? null : nullChecks.toArray(new Statement[nullChecks.size()]); - constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]); + constructor.statements = nullChecks.isEmpty() ? null : nullChecks.toArray(new Statement[0]); + constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[0]); /* Generate annotations that must be put on the generated method, and attach them. */ { Annotation[] constructorProperties = null; @@ -550,8 +550,8 @@ public class HandleConstructor { params.add(parameter); } - statement.arguments = assigns.isEmpty() ? null : assigns.toArray(new Expression[assigns.size()]); - constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]); + statement.arguments = assigns.isEmpty() ? null : assigns.toArray(new Expression[0]); + constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[0]); constructor.statements = new Statement[] { new ReturnStatement(statement, (int) (p >> 32), (int)p) }; constructor.traverse(new SetGeneratedByVisitor(source), typeDecl.scope); diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 84e5185d..046b197f 100644..100755 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -391,7 +391,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH setGeneratedBy(returnStatement, source); statements.add(returnStatement); } - method.statements = statements.toArray(new Statement[statements.size()]); + method.statements = statements.toArray(new Statement[0]); return method; } @@ -738,7 +738,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH setGeneratedBy(returnStatement, source); statements.add(returnStatement); } - method.statements = statements.toArray(new Statement[statements.size()]); + method.statements = statements.toArray(new Statement[0]); return method; } diff --git a/src/core/lombok/eclipse/handlers/HandleHelper.java b/src/core/lombok/eclipse/handlers/HandleHelper.java index 4f06bdfd..36f53813 100644..100755 --- a/src/core/lombok/eclipse/handlers/HandleHelper.java +++ b/src/core/lombok/eclipse/handlers/HandleHelper.java @@ -103,7 +103,7 @@ public class HandleHelper extends EclipseAnnotationHandler<Helper> { } Collections.sort(knownMethodNames); - final String[] knownMethodNames_ = knownMethodNames.toArray(new String[knownMethodNames.size()]); + final String[] knownMethodNames_ = knownMethodNames.toArray(new String[0]); final char[] helperName = new char[annotatedType_.name.length + 1]; final boolean[] helperUsed = new boolean[1]; diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java index 9a3275c2..7b6a3c28 100644..100755 --- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java +++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java @@ -546,7 +546,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { } } - constructor.statements = statements.isEmpty() ? null : statements.toArray(new Statement[statements.size()]); + constructor.statements = statements.isEmpty() ? null : statements.toArray(new Statement[0]); constructor.traverse(new SetGeneratedByVisitor(source), typeDeclaration.scope); @@ -654,7 +654,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { returnCall.selector = SELF_METHOD_NAME; body.add(new ReturnStatement(returnCall, 0, 0)); - out.statements = body.isEmpty() ? null : body.toArray(new Statement[body.size()]); + out.statements = body.isEmpty() ? null : body.toArray(new Statement[0]); return out; } @@ -694,7 +694,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { body.add(exec); } - out.statements = body.isEmpty() ? null : body.toArray(new Statement[body.size()]); + out.statements = body.isEmpty() ? null : body.toArray(new Statement[0]); return out; } @@ -788,7 +788,7 @@ public class HandleSuperBuilder extends EclipseAnnotationHandler<SuperBuilder> { // Use a constructor that only has this builder as parameter. allocationStatement.arguments = new Expression[] {new ThisReference(0, 0)}; statements.add(new ReturnStatement(allocationStatement, 0, 0)); - out.statements = statements.isEmpty() ? null : statements.toArray(new Statement[statements.size()]); + out.statements = statements.isEmpty() ? null : statements.toArray(new Statement[0]); out.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return out; } diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java index 4b094a9f..40f01ee4 100644..100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java @@ -149,7 +149,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { thisDotFieldDotAdd.selector = getAddMethodName().toCharArray(); statements.add(thisDotFieldDotAdd); if (returnStatement != null) statements.add(returnStatement); - md.statements = statements.toArray(new Statement[statements.size()]); + md.statements = statements.toArray(new Statement[0]); md.arguments = new Argument[suffixes.size()]; for (int i = 0; i < suffixes.size(); i++) { TypeReference tr = cloneParamType(i, data.getTypeArgs(), builderType); @@ -183,7 +183,7 @@ abstract class EclipseGuavaSingularizer extends EclipseSingularizer { statements.add(thisDotFieldDotAddAll); if (returnStatement != null) statements.add(returnStatement); - md.statements = statements.toArray(new Statement[statements.size()]); + md.statements = statements.toArray(new Statement[0]); TypeReference paramType; paramType = new QualifiedTypeReference(fromQualifiedName(getAddAllTypeName()), NULL_POSS); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java index 11314bd3..32b1f71f 100644..100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java @@ -140,7 +140,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula statements.add(thisDotFieldDotAdd); if (returnStatement != null) statements.add(returnStatement); - md.statements = statements.toArray(new Statement[statements.size()]); + md.statements = statements.toArray(new Statement[0]); TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType); Annotation[] typeUseAnns = getTypeUseAnnotations(paramType); removeTypeUseAnnotations(paramType); @@ -172,7 +172,7 @@ abstract class EclipseJavaUtilListSetSingularizer extends EclipseJavaUtilSingula statements.add(thisDotFieldDotAddAll); if (returnStatement != null) statements.add(returnStatement); - md.statements = statements.toArray(new Statement[statements.size()]); + md.statements = statements.toArray(new Statement[0]); TypeReference paramType = new QualifiedTypeReference(TypeConstants.JAVA_UTIL_COLLECTION, NULL_POSS); paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs()); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java index f512bacf..80d49fe7 100644..100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java @@ -115,7 +115,7 @@ public class EclipseJavaUtilListSingularizer extends EclipseJavaUtilListSetSingu } SwitchStatement switchStat = new SwitchStatement(); - switchStat.statements = switchContents.toArray(new Statement[switchContents.size()]); + switchStat.statements = switchContents.toArray(new Statement[0]); switchStat.expression = getSize(builderType, data.getPluralName(), true, builderVariable); TypeReference localShadowerType = new QualifiedTypeReference(Eclipse.fromQualifiedName(data.getTargetFqn()), NULL_POSS); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java index 55f6cadd..b24bf97f 100644..100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java @@ -215,7 +215,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer } if (returnStatement != null) statements.add(returnStatement); - md.statements = statements.toArray(new Statement[statements.size()]); + md.statements = statements.toArray(new Statement[0]); TypeReference keyParamType = cloneParamType(0, data.getTypeArgs(), builderType); TypeReference valueParamType = cloneParamType(1, data.getTypeArgs(), builderType); Annotation[] typeUseAnnsKey = getTypeUseAnnotations(keyParamType); @@ -286,7 +286,7 @@ public class EclipseJavaUtilMapSingularizer extends EclipseJavaUtilSingularizer statements.add(forEach); if (returnStatement != null) statements.add(returnStatement); - md.statements = statements.toArray(new Statement[statements.size()]); + md.statements = statements.toArray(new Statement[0]); TypeReference paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs()); diff --git a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java index 8bcfa65d..8aeffc48 100644..100755 --- a/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java +++ b/src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java @@ -147,7 +147,7 @@ abstract class EclipseJavaUtilSingularizer extends EclipseSingularizer { } SwitchStatement switchStat = new SwitchStatement(); - switchStat.statements = switchContents.toArray(new Statement[switchContents.size()]); + switchStat.statements = switchContents.toArray(new Statement[0]); switchStat.expression = getSize(builderType, keyName, true, builderVariable); TypeReference localShadowerType = new QualifiedTypeReference(fromQualifiedName(data.getTargetFqn()), NULL_POSS); diff --git a/src/core/lombok/javac/handlers/HandleHelper.java b/src/core/lombok/javac/handlers/HandleHelper.java index 09ace4d6..6f4361c1 100644..100755 --- a/src/core/lombok/javac/handlers/HandleHelper.java +++ b/src/core/lombok/javac/handlers/HandleHelper.java @@ -102,7 +102,7 @@ public class HandleHelper extends JavacAnnotationHandler<Helper> { } Collections.sort(knownMethodNames); - final String[] knownMethodNames_ = knownMethodNames.toArray(new String[knownMethodNames.size()]); + final String[] knownMethodNames_ = knownMethodNames.toArray(new String[0]); final Name helperName = annotationNode.toName("$" + annotatedType_.name); final boolean[] helperUsed = new boolean[1]; |