Skip to content

Commit

Permalink
Cleanup - Simplify toArray() calls
Browse files Browse the repository at this point in the history
Don't use pre-sized array when calling toArray().
performance-wise pre-sized arrays are not even faster - see https://shipilev.net/blog/2016/arrays-wisdom-ancients/
  • Loading branch information
darxriggs committed Feb 14, 2019
1 parent 15b92e2 commit 288464d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
Expand Up @@ -1005,8 +1005,8 @@ public Object call() throws Exception {
* a cancellation.
*/
private List<String> listProperties(String properties) {
List<String> props = new ArrayList<String>(Arrays.asList(properties.split(",")));
for (String p : props.toArray(new String[props.size()])) {
List<String> props = new CopyOnWriteArrayList<>(properties.split(","));
for (String p : props) {
if (p.startsWith("-")) {
props.remove(p);
props.remove(p.substring(1));
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Expand Up @@ -153,6 +153,7 @@
import java.util.TreeSet;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -847,7 +848,7 @@ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundEx
auths.add(new GrantedAuthorityImpl(g));
}
}
return new org.acegisecurity.userdetails.User(username,"",true,true,true,true, auths.toArray(new GrantedAuthority[auths.size()]));
return new org.acegisecurity.userdetails.User(username,"",true,true,true,true, auths.toArray(new GrantedAuthority[0]));
}

@Override
Expand Down Expand Up @@ -1422,8 +1423,8 @@ public Object call() throws Exception {
* a cancellation.
*/
private List<String> listProperties(String properties) {
List<String> props = new ArrayList<String>(Arrays.asList(properties.split(",")));
for (String p : props.toArray(new String[props.size()])) {
List<String> props = new CopyOnWriteArrayList<>(properties.split(","));
for (String p : props) {
if (p.startsWith("-")) {
props.remove(p);
props.remove(p.substring(1));
Expand Down

0 comments on commit 288464d

Please sign in to comment.