freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject incubator-freemarker git commit: ?keys an ?values now returns a TemplateCollectionModel instead of a TemplateSequenceModel for concatenated hashes as well.
Date Tue, 05 Sep 2017 20:49:11 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/3 cece2e1cb -> 0b7d96596


?keys an ?values now returns a TemplateCollectionModel instead of a TemplateSequenceModel
for concatenated hashes as well.


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

Branch: refs/heads/3
Commit: 0b7d9659605434c7c9aa04c2af52bcc8e42db553
Parents: cece2e1
Author: ddekany <ddekany@apache.org>
Authored: Tue Sep 5 22:49:04 2017 +0200
Committer: ddekany <ddekany@apache.org>
Committed: Tue Sep 5 22:49:04 2017 +0200

----------------------------------------------------------------------
 .../freemarker/core/ASTExpAddOrConcat.java      | 41 +++++++++-----------
 1 file changed, 19 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/0b7d9659/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpAddOrConcat.java
----------------------------------------------------------------------
diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpAddOrConcat.java
b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpAddOrConcat.java
index b821b44..6f7670d 100644
--- a/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpAddOrConcat.java
+++ b/freemarker-core/src/main/java/org/apache/freemarker/core/ASTExpAddOrConcat.java
@@ -19,7 +19,9 @@
 
 package org.apache.freemarker.core;
 
+import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.freemarker.core.arithmetic.ArithmeticEngine;
@@ -267,11 +269,9 @@ final class ASTExpAddOrConcat extends ASTExpression {
         }
     }
 
-    private static final class ConcatenatedHashEx extends ConcatenatedHash
-    implements TemplateHashModelEx {
-        private TemplateSequenceModel keys;
-        private TemplateSequenceModel values;
-        private int size;
+    private static final class ConcatenatedHashEx extends ConcatenatedHash implements TemplateHashModelEx
{
+        private TemplateCollectionModel keys;
+        private TemplateCollectionModel values;
 
         ConcatenatedHashEx(TemplateHashModelEx left, TemplateHashModelEx right) {
             super(left, right);
@@ -280,7 +280,7 @@ final class ASTExpAddOrConcat extends ASTExpression {
         @Override
         public int getHashSize() throws TemplateException {
             initKeys();
-            return size;
+            return keys.getCollectionSize();
         }
 
         @Override
@@ -298,37 +298,34 @@ final class ASTExpAddOrConcat extends ASTExpression {
         private void initKeys() throws TemplateException {
             if (keys == null) {
                 HashSet keySet = new HashSet();
-                NativeSequence keySeq = new NativeSequence(32);
-                addKeys(keySet, keySeq, (TemplateHashModelEx) left);
-                addKeys(keySet, keySeq, (TemplateHashModelEx) right);
-                size = keySet.size();
-                keys = keySeq;
+                ArrayList<TemplateModel> keyList = new ArrayList<>();
+                addKeys(keySet, keyList, (TemplateHashModelEx) left);
+                addKeys(keySet, keyList, (TemplateHashModelEx) right);
+                keys = new NativeCollection(keyList);
             }
         }
 
-        private static void addKeys(Set set, NativeSequence keySeq, TemplateHashModelEx hash)
+        private static void addKeys(Set keySet, List<TemplateModel> keyList, TemplateHashModelEx
hash)
         throws TemplateException {
-            TemplateModelIterator it = hash.keys().iterator();
-            while (it.hasNext()) {
+            for (TemplateModelIterator it = hash.keys().iterator(); it.hasNext(); ) {
                 TemplateStringModel tsm = (TemplateStringModel) it.next();
-                if (set.add(tsm.getAsString())) {
+                if (keySet.add(tsm.getAsString())) {
                     // The first occurrence of the key decides the index;
                     // this is consistent with stuff like java.util.LinkedHashSet.
-                    keySeq.add(tsm);
+                    keyList.add(tsm);
                 }
             }
         }        
 
         private void initValues() throws TemplateException {
             if (values == null) {
-                NativeSequence seq = new NativeSequence(getHashSize());
-                // Note: getCollectionSize() invokes initKeys() if needed.
+                ArrayList<TemplateModel> valueList = new ArrayList<>(getHashSize());
+                // Note: getHashSize() invokes initKeys()
             
-                int ln = keys.getCollectionSize();
-                for (int i  = 0; i < ln; i++) {
-                    seq.add(get(((TemplateStringModel) keys.get(i)).getAsString()));
+                for (TemplateModelIterator iter = keys.iterator(); iter.hasNext(); ) {
+                    valueList.add(get(((TemplateStringModel) iter.next()).getAsString()));
                 }
-                values = seq;
+                values = new NativeCollection(valueList);
             }
         }
     }


Mime
View raw message