freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [13/50] [abbrv] incubator-freemarker git commit: MultiTemplateLoader, when it's in sticky mode (the default), and the TemplateLoader that was successfully used for a given name last time doesn't find the template now (let's call it the sticked TemplateLo
Date Wed, 01 Mar 2017 14:21:11 GMT
MultiTemplateLoader, when it's in sticky mode (the default), and the TemplateLoader that was
successfully used for a given name last time doesn't find the template now (let's call it
the sticked TemplateLoader), and thus MultiTemplateLoader falls back to trying all the TemplateLoader-s
in order, will now skip the sticked TemplateLoader, as that was already attempted in the same
MultiTemplateLoader.findTemplateSource invocation.


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

Branch: refs/heads/2.3
Commit: 6837e4c532ed91357fa18aa0fe3d06cf13cdcb51
Parents: 708097f
Author: ddekany <ddekany@apache.org>
Authored: Wed Feb 8 01:07:18 2017 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Wed Feb 8 01:07:34 2017 +0100

----------------------------------------------------------------------
 .../freemarker/cache/MultiTemplateLoader.java     | 18 ++++++++++--------
 src/manual/en_US/book.xml                         | 14 ++++++++++++++
 2 files changed, 24 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6837e4c5/src/main/java/freemarker/cache/MultiTemplateLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/cache/MultiTemplateLoader.java b/src/main/java/freemarker/cache/MultiTemplateLoader.java
index c86baa3..5457a88 100644
--- a/src/main/java/freemarker/cache/MultiTemplateLoader.java
+++ b/src/main/java/freemarker/cache/MultiTemplateLoader.java
@@ -52,10 +52,11 @@ public class MultiTemplateLoader implements StatefulTemplateLoader {
 
     public Object findTemplateSource(String name)
             throws IOException {
+        TemplateLoader lastLoader = null;
         if (sticky) {
             // Use soft affinity - give the loader that last found this
             // resource a chance to find it again first.
-            TemplateLoader lastLoader = lastLoaderForName.get(name);
+            lastLoader = lastLoaderForName.get(name);
             if (lastLoader != null) {
                 Object source = lastLoader.findTemplateSource(name);
                 if (source != null) {
@@ -68,14 +69,15 @@ public class MultiTemplateLoader implements StatefulTemplateLoader {
         // again, try all loaders in order of appearance. If any manages
         // to find the resource, then associate it as the new affine loader
         // for this resource.
-        for (int i = 0; i < loaders.length; ++i) {
-            TemplateLoader loader = loaders[i];
-            Object source = loader.findTemplateSource(name);
-            if (source != null) {
-                if (sticky) {
-                    lastLoaderForName.put(name, loader);
+        for (TemplateLoader loader : loaders) {
+            if (lastLoader != loader) {
+                Object source = loader.findTemplateSource(name);
+                if (source != null) {
+                    if (sticky) {
+                        lastLoaderForName.put(name, loader);
+                    }
+                    return new MultiSource(source, loader);
                 }
-                return new MultiSource(source, loader);
             }
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/6837e4c5/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index 9be62fd..2e9015b 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -26834,6 +26834,20 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
             </listitem>
 
             <listitem>
+              <para><literal>MultiTemplateLoader</literal>, when it's in
+              sticky mode (the default), and the
+              <literal>TemplateLoader</literal> that was successfully used for
+              a given name last time doesn't find the template now (let's call
+              it the sticked <literal>TemplateLoader</literal>), and thus
+              <literal>MultiTemplateLoader</literal> falls back to trying all
+              the <literal>TemplateLoader</literal>-s in order, will now skip
+              the sticked <literal>TemplateLoader</literal>, as that was
+              already attempted in the same
+              <literal>MultiTemplateLoader.findTemplateSource</literal>
+              invocation.</para>
+            </listitem>
+
+            <listitem>
               <para>Bug fixed:
               <literal>NodeModel.mergeAdjacentText(Node)</literal> didn't
               merged all adjacent text nodes, only pairs of adjacent text


Mime
View raw message