Skip to content

Commit

Permalink
Performance enhancements.
Browse files Browse the repository at this point in the history
 * Dealing with POJO data is way way faster.
 * Conditionals are now "compiled" for speed gain.
 * slice, reverse and get filters now work on STRING type data, not just LIST type.
 * Parens are now optional for simple if conditions.
 * TemplateConfig now easier to use programmatically.
 * Allows default extension of none to be set from config.
 * Easier to set arbitrary template folder.
  • Loading branch information
Tom McClure committed Nov 16, 2015
1 parent 82eeb15 commit 0d3f6fd
Show file tree
Hide file tree
Showing 25 changed files with 862 additions and 672 deletions.
15 changes: 11 additions & 4 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
Release History

v3.1.0 - 2015-11-15 tmcclure

Performance enhancements.
slice, reverse and get filters now work on STRING type data, not just LIST type.
Parens are now optional for simple if conditions.
TemplateConfig now easier to use programmatically.

v3.0.2 - 2015-10-30 tmcclure

Fixes bugs: looping over wrapped map, looping over POJO with null values
Fixes bugs: looping over wrapped map, looping over POJO with null values.

v3.0.1 - 2015-07-16 tmcclure

Expand Down Expand Up @@ -98,18 +105,18 @@ v2.1 - New {$tag|filter(#x_template)} runs the #x_template snippet as
Easier access to POJO attributes and bean properties:
* chunk.setToBean('my_thing', someObject)
copies someObject's public accessor properties to a Map
so the template can do this:
so the template can do this:
{$my_thing.price}
to get the value of
someObject.getPrice()
* chunk.set('item', somePOJO)
copies somePOJO's non-private attributes to a Map
so the template can do this:
so the template can do this:
{$item.price}
to get the value of
somePOJO.price
* Map values seen by template renderer are a snapshot from
time of first attribute access.
time of first attribute access.

v2.0 - Refactored for 20% speed gain.
New |type filter {$what_am_i|type} outputs one of the following:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Available from Maven Central:
<dependency>
<groupId>com.x5dev</groupId>
<artifactId>chunk-templates</artifactId>
<version>3.0.2</version>
<version>3.1.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.x5dev</groupId>
<artifactId>chunk-templates</artifactId>
<packaging>jar</packaging>
<version>3.0.2</version>
<version>3.1.0</version>
<name>Chunk Templates</name>
<description>Chunk Template Engine for Java</description>
<url>http://www.x5software.com/chunk/</url>
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/x5/template/Chunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@
* Updates: <A href="http://www.x5software.com/chunk/">Chunk Documentation</A><BR>
*
* @author Tom McClure
* @version 3.0.2
* @version 3.1.0
*/

public class Chunk implements Map<String,Object>
{
public static final int HASH_THRESH = 8;
public static final int DEPTH_LIMIT = 17;

public static final String VERSION = "3.0.2";
public static final String VERSION = "3.1.0";

private static final String TRUE = "TRUE";

Expand Down Expand Up @@ -1028,7 +1028,7 @@ protected Object _resolveTagValue(SnippetTag tag, int depth, boolean ignoreParen
int segment = 0;
String segmentName = path[segment];

if (segmentName.indexOf('`') > -1) {
if (tag.hasBackticks()) {
segmentName = resolveBackticks(segmentName, depth);
}

Expand Down Expand Up @@ -1058,7 +1058,10 @@ protected Object _resolveTagValue(SnippetTag tag, int depth, boolean ignoreParen
// or path-map hits dead end
while (path.length > segment && tagValue != null) {
if (tagValue instanceof Map) {
segmentName = resolveBackticks(path[segment], depth);
segmentName = path[segment];
if (tag.hasBackticks()) {
segmentName = resolveBackticks(segmentName, depth);
}
Map obj = (Map)tagValue;
tagValue = obj.get(segmentName);
segment++;
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/x5/template/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,28 @@ public static Object applyFilter(Chunk context, String filter, Object input)
return typeFilter(context, input);
}

if (input instanceof String || input instanceof Snippet) {
String text = null;
if (input instanceof String) {
text = (String)input;
} else if (input instanceof Snippet) {
text = ((Snippet)input).toSimpleString();
}

if (text != null) {
// provide a few core filters without making a whole class for each one.
String text = BasicFilter.stringify(input);
if (filter.equals("trim")) {
// trim leading and trailing whitespace
return text == null ? null : text.trim(); //text.replaceAll("^\\s+","").replaceAll("\\s+$","");
return text.trim(); //text.replaceAll("^\\s+","").replaceAll("\\s+$","");
} else if (filter.startsWith("join(")) {
if (text != null) {
TableData array = InlineTable.parseTable(text);
if (array != null) {
return joinInlineTable(array, filterArgs);
}
TableData array = InlineTable.parseTable(text);
if (array != null) {
return joinInlineTable(array, filterArgs);
}
} else if (filter.startsWith("get(")) {
if (text != null) {
TableData array = InlineTable.parseTable(text);
if (array != null) {
return accessArrayIndex(array, filterArgs);
}
TableData array = InlineTable.parseTable(text);
if (array != null) {
return accessArrayIndex(array, filterArgs);
}
} else if (filter.equals("type")) {
return "STRING";
}
}

Expand Down
Loading

0 comments on commit 0d3f6fd

Please sign in to comment.