freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject incubator-freemarker git commit: FREEMARKER-55: no list needed; use array simply in new #of()
Date Sat, 06 Jan 2018 04:19:57 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 def59eb43 -> 7887a9208


FREEMARKER-55: no list needed; use array simply in new #of()


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/7887a920
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/7887a920
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/7887a920

Branch: refs/heads/3
Commit: 7887a9208f9361b8512fb00fbc7d56841d3e6050
Parents: def59eb
Author: Woonsan Ko <woonsan@apache.org>
Authored: Fri Jan 5 23:18:44 2018 -0500
Committer: Woonsan Ko <woonsan@apache.org>
Committed: Fri Jan 5 23:18:44 2018 -0500

----------------------------------------------------------------------
 .../freemarker/core/util/StringToIndexMap.java  | 35 ++++++++------------
 1 file changed, 13 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7887a920/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
index a2248b1..4d9a150 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/util/StringToIndexMap.java
@@ -19,8 +19,6 @@
 
 package org.apache.freemarker.core.util;
 
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -141,12 +139,20 @@ public final class StringToIndexMap {
      */
     public static StringToIndexMap of(StringToIndexMap baseMap, Entry... additionalEntries)
{
         final int additionalEntriesLength = (additionalEntries != null) ? additionalEntries.length
: 0;
-        List<Entry> newEntries = new ArrayList<>(baseMap.size() + additionalEntriesLength);
-        baseMap.collectAllEntriesInto(newEntries);
-        for (int i = 0; i < additionalEntriesLength; i++) {
-            newEntries.add(additionalEntries[i]);
+        Entry[] newEntries = new Entry[baseMap.size() + additionalEntriesLength];
+        int index = 0;
+        if (baseMap.buckets != null) {
+            for (Entry entry : baseMap.buckets) {
+                while (entry != null) {
+                    newEntries[index++] = entry;
+                    entry = entry.nextInSameBucket;
+                }
+            }
         }
-        return of(newEntries.toArray(new Entry[newEntries.size()]));
+        if (additionalEntriesLength > 0) {
+            System.arraycopy(additionalEntries, 0, newEntries, index, additionalEntriesLength);
+        }
+        return of(newEntries);
     }
 
     // This is a very frequent case, so we optimize for it a bit.
@@ -354,21 +360,6 @@ public final class StringToIndexMap {
         return null;
     }
 
-    /**
-     * Traverse all the entries and collect all into the given {@code targetEntryCollection}.
-     */
-    private void collectAllEntriesInto(Collection<Entry> targetEntryCollection) {
-        if (buckets == null) {
-            return;
-        }
-        for (Entry entry : buckets) {
-            while (entry != null) {
-                targetEntryCollection.add(entry);
-                entry = entry.nextInSameBucket;
-            }
-        }
-    }
-
     /*
     // Code used to see how well the elements are spread among the buckets:
 


Mime
View raw message