diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-06-14 12:43:45 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-06-14 12:43:45 +0200 |
commit | 3bfcc347d1399e8b3ec17c8c8cf01b63a6b88d9b (patch) | |
tree | 2f9815469fb5e532a3adc204f6fcb80e2a7fb8f5 /processing | |
parent | 436735628ef9428187fea8d3c7a5aecd3477784d (diff) |
Use an immutable singleton until you really need a list. Then be explicit about initial size.
Diffstat (limited to 'processing')
-rw-r--r-- | processing/src/main/java/com/yahoo/processing/request/CompoundName.java | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/processing/src/main/java/com/yahoo/processing/request/CompoundName.java b/processing/src/main/java/com/yahoo/processing/request/CompoundName.java index 43add084542..976fb3e2796 100644 --- a/processing/src/main/java/com/yahoo/processing/request/CompoundName.java +++ b/processing/src/main/java/com/yahoo/processing/request/CompoundName.java @@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static com.yahoo.text.Lowercase.toLowerCase; @@ -79,17 +80,19 @@ public final class CompoundName { } private static List<String> parse(String s) { - ArrayList<String> l = new ArrayList<>(); + ArrayList<String> l = null; + int p = 0; final int m = s.length(); for (int i = 0; i < m; i++) { if (s.charAt(i) == '.') { + if (l == null) l = new ArrayList<>(8); l.add(s.substring(p, i)); p = i + 1; } } if (p == 0) { - l.add(s); + return ImmutableList.of(s); } else if (p < m) { l.add(s.substring(p, m)); } else { |