maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slachiew...@apache.org
Subject [maven] 01/01: [MNG-6492] - Minor improvement on Array construction, conversion performance
Date Thu, 18 Oct 2018 20:36:28 GMT
This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch slach-pre-merge-master
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 5037d3738cfbb5e76b7f96e261598cb95e433d12
Author: HoaPhan <hoaphan@atlassian.com>
AuthorDate: Sat Sep 8 22:46:22 2018 +1000

    [MNG-6492] - Minor improvement on Array construction, conversion performance
    
    Fixes  #186
---
 maven-compat/src/main/java/org/apache/maven/project/ModelUtils.java | 6 +-----
 .../maven/repository/metadata/DefaultClasspathTransformation.java   | 2 +-
 .../main/java/org/apache/maven/project/ProjectModelResolver.java    | 5 ++---
 .../org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java  | 2 +-
 .../org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java  | 5 +----
 .../src/main/java/org/apache/maven/cli/CleanArgument.java           | 2 +-
 maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java     | 4 ++--
 .../maven/model/interpolation/StringSearchModelInterpolator.java    | 3 +--
 .../org/apache/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 fb99593..9bcc384 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<Repository> mergeRepositoryLists( List<Repository> dominant,
List<Repository> recessive )
     {
-        List<Repository> repositories = new ArrayList<>();
 
-        for ( Repository repository : dominant )
-        {
-            repositories.add( repository );
-        }
+        List<Repository> 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 b6e3c0c..f980f5a 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<MetadataGraphEdge>()
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 2b3108a..24b36dd 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<RemoteRepository> 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 40db389..1591573 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 a8572ff..8a6580b 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<MojoExecution> 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 8b2d9b7..08403b6 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 6a1a34a..f7ceda2 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 c95cacb..25982cd 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 6818453..338f4ff 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<RemoteRepository> externalRepositories = new ArrayList<>();
-        externalRepositories.addAll( repositories );
-        this.externalRepositories = Collections.unmodifiableList( externalRepositories );
+        this.externalRepositories = Collections.unmodifiableList( new ArrayList<>(
repositories ) );
 
         this.repositoryIds = new HashSet<>();
     }


Mime
View raw message