From ba74b96633af63300e31d8afe64405a386f68645 Mon Sep 17 00:00:00 2001 From: HoaPhan Date: Sat, 8 Sep 2018 22:46:22 +1000 Subject: [PATCH] [MNG-6492] - Minor improvement on Array construction, conversion performance --- .../src/main/java/org/apache/maven/project/ModelUtils.java | 6 +----- .../repository/metadata/DefaultClasspathTransformation.java | 2 +- .../java/org/apache/maven/project/ProjectModelResolver.java | 5 ++--- .../maven/toolchain/DefaultToolchainManagerPrivate.java | 2 +- .../maven/lifecycle/internal/stub/MojoExecutorStub.java | 5 +---- .../src/main/java/org/apache/maven/cli/CleanArgument.java | 2 +- .../src/main/java/org/apache/maven/cli/MavenCli.java | 4 ++-- .../model/interpolation/StringSearchModelInterpolator.java | 3 +-- .../maven/repository/internal/DefaultModelResolver.java | 4 +--- 9 files changed, 11 insertions(+), 22 deletions(-) diff --git a/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java b/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java index fb99593c90..9bcc384234 100644 --- a/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java +++ b/maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java @@ -313,12 +313,8 @@ public final class ModelUtils public static List mergeRepositoryLists( List dominant, List recessive ) { - List repositories = new ArrayList<>(); - for ( Repository repository : dominant ) - { - repositories.add( repository ); - } + List repositories = new ArrayList<>( dominant ); for ( Repository repository : recessive ) { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java index b6e3c0c96e..f980f5ab47 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java @@ -139,7 +139,7 @@ public class DefaultClasspathTransformation if ( exits != null && exits.size() > 0 ) { - MetadataGraphEdge[] sortedExits = exits.toArray( new MetadataGraphEdge[exits.size()] ); + MetadataGraphEdge[] sortedExits = exits.toArray( new MetadataGraphEdge[0] ); Arrays.sort( sortedExits , new Comparator() diff --git a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java index 2b3108a47f..24b36dda31 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/ProjectModelResolver.java @@ -49,6 +49,7 @@ import org.eclipse.aether.resolution.VersionRangeRequest; import org.eclipse.aether.resolution.VersionRangeResolutionException; import org.eclipse.aether.resolution.VersionRangeResult; + /** * A model resolver to assist building of projects. This resolver gives priority to those repositories that have been * declared in the POM. @@ -91,9 +92,7 @@ public class ProjectModelResolver this.resolver = resolver; this.remoteRepositoryManager = remoteRepositoryManager; this.pomRepositories = new ArrayList<>(); - List externalRepositories = new ArrayList<>(); - externalRepositories.addAll( repositories ); - this.externalRepositories = Collections.unmodifiableList( externalRepositories ); + this.externalRepositories = Collections.unmodifiableList( new ArrayList<>( repositories ) ); this.repositories = new ArrayList<>(); this.repositories.addAll( externalRepositories ); this.repositoryMerging = repositoryMerging; diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java index 40db38994d..1591573f62 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java @@ -69,7 +69,7 @@ public class DefaultToolchainManagerPrivate } } - return toRet.toArray( new ToolchainPrivate[toRet.size()] ); + return toRet.toArray( new ToolchainPrivate[0] ); } @Override diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java index a8572ffc9f..8a6580b699 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java @@ -50,10 +50,7 @@ public class MojoExecutorStub public void execute( MavenSession session, List mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { - for ( MojoExecution mojoExecution : mojoExecutions ) - { - executions.add( mojoExecution ); - } + executions.addAll(mojoExecutions); } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java b/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java index 8b2d9b70ab..08403b649d 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/CleanArgument.java @@ -115,7 +115,7 @@ public class CleanArgument } else { - cleanArgs = cleaned.toArray( new String[cleanedSz] ); + cleanArgs = cleaned.toArray( new String[0] ); } return cleanArgs; diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index 6a1a34ad55..f7ceda2422 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -384,7 +384,7 @@ public class MavenCli } } - mavenConfig = cliManager.parse( args.toArray( new String[args.size()] ) ); + mavenConfig = cliManager.parse( args.toArray( new String[0] ) ); List unrecongized = mavenConfig.getArgList(); if ( !unrecongized.isEmpty() ) { @@ -1196,7 +1196,7 @@ public class MavenCli sb.append( String.format( "%s\n", configurationProcessor.getClass().getName() ) ); } } - sb.append( String.format( "\n" ) ); + sb.append( "\n" ); throw new Exception( sb.toString() ); } } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java index c95cacbfd7..25982cd6d8 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java @@ -263,9 +263,8 @@ public class StringSearchModelInterpolator fields.add( new ObjectField( currentField ) ); } } - } - this.fields = fields.toArray( new CacheField[fields.size()] ); + this.fields = fields.toArray( new CacheField[0] ); } diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java index 6818453469..338f4ff8ad 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultModelResolver.java @@ -89,9 +89,7 @@ class DefaultModelResolver this.versionRangeResolver = versionRangeResolver; this.remoteRepositoryManager = remoteRepositoryManager; this.repositories = repositories; - List externalRepositories = new ArrayList<>(); - externalRepositories.addAll( repositories ); - this.externalRepositories = Collections.unmodifiableList( externalRepositories ); + this.externalRepositories = Collections.unmodifiableList( new ArrayList<>( repositories ) ); this.repositoryIds = new HashSet<>(); }