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 | |
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.
17 files changed, 31 insertions, 30 deletions
@@ -24,6 +24,7 @@ Philippe Charles <philippe.charles@nbb.be> Rabea Gransberger <rgra@users.noreply.github.com> Reinier Zwitserloot <reinier@zwitserloot.com> Robbert Jan Grootjans <grootjans@gmail.com> +Robert Wertman <robert.wertman@gmail.com> Roel Spilker <r.spilker@gmail.com> Roland Praml <pram@gmx.de> Sander Koning <askoning@gmail.com> 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]; diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java index 69898668..9582c3b8 100644..100755 --- a/src/delombok/lombok/delombok/Delombok.java +++ b/src/delombok/lombok/delombok/Delombok.java @@ -426,7 +426,7 @@ public class Delombok { throw new IOException("Unclosed ' in @ file"); } - return x.toArray(new String[x.size()]); + return x.toArray(new String[0]); } public static class InvalidFormatOptionException extends Exception { diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java index ace97a4d..085c903f 100644..100755 --- a/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java +++ b/src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java @@ -78,7 +78,7 @@ public class PatchExtensionMethodCompletionProposal { } } } - return proposals.toArray(new IJavaCompletionProposal[proposals.size()]); + return proposals.toArray(new IJavaCompletionProposal[0]); } diff --git a/src/eclipseAgent/lombok/launch/PatchFixesHider.java b/src/eclipseAgent/lombok/launch/PatchFixesHider.java index 3c70d81d..5c409603 100644..100755 --- a/src/eclipseAgent/lombok/launch/PatchFixesHider.java +++ b/src/eclipseAgent/lombok/launch/PatchFixesHider.java @@ -551,7 +551,7 @@ final class PatchFixesHider { // Since Eclipse doesn't honor the "insert at specified location" for already existing members, // we'll just add them last newChildren.addAll(modifiedChildren); - return newChildren.toArray(new RewriteEvent[newChildren.size()]); + return newChildren.toArray(new RewriteEvent[0]); } public static int getTokenEndOffsetFixed(TokenScanner scanner, int token, int startOffset, Object domNode) throws CoreException { @@ -570,7 +570,7 @@ final class PatchFixesHider { for (IMethod m : methods) { if (m.getNameRange().getLength() > 0 && !m.getNameRange().equals(m.getSourceRange())) result.add(m); } - return result.size() == methods.length ? methods : result.toArray(new IMethod[result.size()]); + return result.size() == methods.length ? methods : result.toArray(new IMethod[0]); } public static SearchMatch[] removeGenerated(SearchMatch[] returnValue) { @@ -591,7 +591,7 @@ final class PatchFixesHider { } result.add(searchResult); } - return result.toArray(new SearchMatch[result.size()]); + return result.toArray(new SearchMatch[0]); } public static SearchResultGroup[] createFakeSearchResult(SearchResultGroup[] returnValue, |