You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2015/12/14 23:51:16 UTC

[2/4] incubator-freemarker git commit: (Just local variable name fixes, and one more AST test)

(Just local variable name fixes, and one more AST test)


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

Branch: refs/heads/2.3-gae
Commit: 1cb2a5fa8167ae34e59cc940617a31459300d91c
Parents: a31cf2a
Author: ddekany <dd...@apache.org>
Authored: Mon Dec 14 22:44:17 2015 +0100
Committer: ddekany <dd...@apache.org>
Committed: Mon Dec 14 22:44:17 2015 +0100

----------------------------------------------------------------------
 .../java/freemarker/core/TemplateElement.java   | 32 ++++++++++----------
 src/test/java/freemarker/core/ASTTest.java      |  4 +++
 .../core/ast-multipleignoredchildren.ast        | 12 ++++++++
 .../core/ast-multipleignoredchildren.ftl        | 15 +++++++++
 4 files changed, 47 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1cb2a5fa/src/main/java/freemarker/core/TemplateElement.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/TemplateElement.java b/src/main/java/freemarker/core/TemplateElement.java
index 350bfa1..4cf195b 100644
--- a/src/main/java/freemarker/core/TemplateElement.java
+++ b/src/main/java/freemarker/core/TemplateElement.java
@@ -350,9 +350,9 @@ abstract public class TemplateElement extends TemplateObject {
      *         is the duty of the caller, not of this method.
      */
     TemplateElement postParseCleanup(boolean stripWhitespace) throws ParseException {
-        int regulatedChildCount = this.childCount;
-        if (regulatedChildCount != 0) {
-            for (int i = 0; i < regulatedChildCount; i++) {
+        int childCount = this.childCount;
+        if (childCount != 0) {
+            for (int i = 0; i < childCount; i++) {
                 TemplateElement te = childBuffer[i];
                 
                 //!!T temporal assertion
@@ -370,30 +370,30 @@ abstract public class TemplateElement extends TemplateObject {
                 te.parent = this;
                 te.index = i;
             }
-            for (int i = 0; i < regulatedChildCount; i++) {
+            for (int i = 0; i < childCount; i++) {
                 TemplateElement te = childBuffer[i];
                 if (te.isIgnorable(stripWhitespace)) {
-                    // TODO Optimize this...
-                    regulatedChildCount--;
-                    for (int j = i; j < regulatedChildCount; j++) {
+                    childCount--;
+                    // As later isIgnorable calls might investigates the siblings, we have to move all the items now. 
+                    for (int j = i; j < childCount; j++) {
                         final TemplateElement te2 = childBuffer[j + 1];
                         childBuffer[j] = te2;
                         te2.index = j;
                     }
-                    childBuffer[regulatedChildCount] = null;
-                    this.childCount = regulatedChildCount;
+                    childBuffer[childCount] = null;
+                    this.childCount = childCount;
                     i--;
                 }
             }
-            if (regulatedChildCount == 0) {
+            if (childCount == 0) {
                 childBuffer = null;
-            } else if (regulatedChildCount < childBuffer.length
-                    && regulatedChildCount <= childBuffer.length * 3 / 4) {
-                TemplateElement[] trimmedregulatedChildBuffer = new TemplateElement[regulatedChildCount];
-                for (int i = 0; i < regulatedChildCount; i++) {
-                    trimmedregulatedChildBuffer[i] = childBuffer[i];
+            } else if (childCount < childBuffer.length
+                    && childCount <= childBuffer.length * 3 / 4) {
+                TemplateElement[] trimmedChildBuffer = new TemplateElement[childCount];
+                for (int i = 0; i < childCount; i++) {
+                    trimmedChildBuffer[i] = childBuffer[i];
                 }
-                childBuffer = trimmedregulatedChildBuffer;
+                childBuffer = trimmedChildBuffer;
             }
         }
         return this;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1cb2a5fa/src/test/java/freemarker/core/ASTTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/ASTTest.java b/src/test/java/freemarker/core/ASTTest.java
index 6ba4378..a700334 100644
--- a/src/test/java/freemarker/core/ASTTest.java
+++ b/src/test/java/freemarker/core/ASTTest.java
@@ -58,6 +58,10 @@ public class ASTTest extends FileTestCase {
     public void testMixedContentSimplifications() throws Exception {
         testAST("ast-mixedcontentsimplifications");
     }
+
+    public void testMultipleIgnoredChildren() throws Exception {
+        testAST("ast-multipleignoredchildren");
+    }
     
     private void testAST(String testName) throws FileNotFoundException, IOException {
         final String templateName = testName + ".ftl";

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1cb2a5fa/src/test/resources/freemarker/core/ast-multipleignoredchildren.ast
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/core/ast-multipleignoredchildren.ast b/src/test/resources/freemarker/core/ast-multipleignoredchildren.ast
new file mode 100644
index 0000000..798e81b
--- /dev/null
+++ b/src/test/resources/freemarker/core/ast-multipleignoredchildren.ast
@@ -0,0 +1,12 @@
+#mixed_content  // f.c.MixedContent
+    #text  // f.c.TextBlock
+        - content: "a\n"  // String
+    #text  // f.c.TextBlock
+        - content: "b\n"  // String
+    #text  // f.c.TextBlock
+        - content: "c\n"  // String
+    #text  // f.c.TextBlock
+        - content: "d\n"  // String
+    #if  // f.c.ConditionalBlock
+        - condition: true  // f.c.BooleanLiteral
+        - AST-node subtype: "0"  // Integer

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/1cb2a5fa/src/test/resources/freemarker/core/ast-multipleignoredchildren.ftl
----------------------------------------------------------------------
diff --git a/src/test/resources/freemarker/core/ast-multipleignoredchildren.ftl b/src/test/resources/freemarker/core/ast-multipleignoredchildren.ftl
new file mode 100644
index 0000000..10b8d87
--- /dev/null
+++ b/src/test/resources/freemarker/core/ast-multipleignoredchildren.ftl
@@ -0,0 +1,15 @@
+a
+<#compress></#compress>
+b
+<#compress></#compress>
+<#compress></#compress>
+c
+<#compress></#compress>
+<#compress></#compress>
+<#compress></#compress>
+d
+<#if true>
+  <#compress></#compress>
+  <#compress></#compress>
+  <#compress></#compress>
+</#if>
\ No newline at end of file