mkarg commented on a change in pull request #68:
URL: https://github.com/apache/maven-shared-utils/pull/68#discussion_r549711299
##########
File path: src/main/java/org/apache/maven/shared/utils/cli/Commandline.java
##########
@@ -241,15 +241,16 @@ public void addSystemEnvironment()
public String[] getEnvironmentVariables()
{
addSystemEnvironment();
- String[] environmentVars = new String[envVars.size()];
- int i = 0;
+ List<String> environmentVars = new ArrayList<>();
for ( String name : envVars.keySet() )
{
String value = envVars.get( name );
- environmentVars[i] = name + "=" + value;
- i++;
+ if ( value != null )
+ {
+ environmentVars.add( name + "=" + value );
+ }
}
- return environmentVars;
+ return environmentVars.toArray( new String[0] );
Review comment:
We could speed up this code a very little bit (some nanoseconds though)
if we use `new String[environmentVars.size()]` instead. It prevents dropping
the empty array and creating a new one, hence reduces GC pressure.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]