From f2d03973d59d96d8bfef51d8378a4069d8d46205 Mon Sep 17 00:00:00 2001 From: Robert Wertman Date: Sun, 27 Jan 2019 00:39:30 -0500 Subject: Replace sized array in toArray with 0 This approach has been benchmarked to be marginally faster. Fixes #2030. --- AUTHORS | 1 + src/core/lombok/core/AST.java | 2 +- src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java | 2 +- src/core/lombok/eclipse/handlers/HandleBuilder.java | 6 +++--- src/core/lombok/eclipse/handlers/HandleConstructor.java | 8 ++++---- src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 4 ++-- src/core/lombok/eclipse/handlers/HandleHelper.java | 2 +- src/core/lombok/eclipse/handlers/HandleSuperBuilder.java | 8 ++++---- .../eclipse/handlers/singulars/EclipseGuavaSingularizer.java | 4 ++-- .../handlers/singulars/EclipseJavaUtilListSetSingularizer.java | 4 ++-- .../handlers/singulars/EclipseJavaUtilListSingularizer.java | 2 +- .../handlers/singulars/EclipseJavaUtilMapSingularizer.java | 4 ++-- .../eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java | 2 +- src/core/lombok/javac/handlers/HandleHelper.java | 2 +- src/delombok/lombok/delombok/Delombok.java | 2 +- .../eclipse/agent/PatchExtensionMethodCompletionProposal.java | 2 +- src/eclipseAgent/lombok/launch/PatchFixesHider.java | 6 +++--- 17 files changed, 31 insertions(+), 30 deletions(-) mode change 100644 => 100755 AUTHORS mode change 100644 => 100755 src/core/lombok/core/AST.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/HandleBuilder.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/HandleConstructor.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/HandleHelper.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/HandleSuperBuilder.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/singulars/EclipseGuavaSingularizer.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSetSingularizer.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilListSingularizer.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilMapSingularizer.java mode change 100644 => 100755 src/core/lombok/eclipse/handlers/singulars/EclipseJavaUtilSingularizer.java mode change 100644 => 100755 src/core/lombok/javac/handlers/HandleHelper.java mode change 100644 => 100755 src/delombok/lombok/delombok/Delombok.java mode change 100644 => 100755 src/eclipseAgent/lombok/eclipse/agent/PatchExtensionMethodCompletionProposal.java mode change 100644 => 100755 src/eclipseAgent/lombok/launch/PatchFixesHider.java diff --git a/AUTHORS b/AUTHORS old mode 100644 new mode 100755 index 05f918c2..251353a3 --- a/AUTHORS +++ b/AUTHORS @@ -24,6 +24,7 @@ Philippe Charles Rabea Gransberger Reinier Zwitserloot Robbert Jan Grootjans +Robert Wertman Roel Spilker Roland Praml Sander Koning diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java old mode 100644 new mode 100755 index 77443ba1..78761f46 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -229,7 +229,7 @@ public abstract class AST, L extends LombokNode, List fieldList = new ArrayList(); 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 old mode 100644 new mode 100755 index b9b9e07d..81ddbd0a --- 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 old mode 100644 new mode 100755 index fc11aff2..890a04bc --- 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 { 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 { 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 old mode 100644 new mode 100755 index 82859e4b..660b9985 --- 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 old mode 100644 new mode 100755 index 84e5185d..046b197f --- 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 { } 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 old mode 100644 new mode 100755 index 9a3275c2..7b6a3c28 --- 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 { } } - 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 { 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 { 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 { // 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 old mode 100644 new mode 100755 index 4b094a9f..40f01ee4 --- 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 old mode 100644 new mode 100755 index 11314bd3..32b1f71f --- 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 old mode 100644 new mode 100755 index f512bacf..80d49fe7 --- 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 old mode 100644 new mode 100755 index 55f6cadd..b24bf97f --- 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 old mode 100644 new mode 100755 index 8bcfa65d..8aeffc48 --- 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 old mode 100644 new mode 100755 index 09ace4d6..6f4361c1 --- 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 { } 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 old mode 100644 new mode 100755 index 69898668..9582c3b8 --- 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 old mode 100644 new mode 100755 index ace97a4d..085c903f --- 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 old mode 100644 new mode 100755 index 3c70d81d..5c409603 --- 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, -- cgit