pzygielo commented on a change in pull request #68:
URL: https://github.com/apache/maven-shared-utils/pull/68#discussion_r549718880
##########
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.
It seems, even across Apache repositories
(https://github.com/apache/kafka/pull/9750,
https://github.com/apache/tika/pull/372), that using empty array exactly is
popular now.
----------------------------------------------------------------
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]