Skip to content

Commit f28e63a

Browse files
committed
Use simpler/faster SqlNode implementation for empty nodes
1 parent 9a66c60 commit f28e63a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/java/org/apache/ibatis/scripting/xmltags/XMLScriptBuilder.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class XMLScriptBuilder extends BaseBuilder {
3939
private boolean isDynamic;
4040
private final Class<?> parameterType;
4141
private final Map<String, NodeHandler> nodeHandlerMap = new HashMap<>();
42-
private final static Map<String, StaticTextSqlNode> EMPTY_TEXT_NODE = new ConcurrentHashMap<>();
42+
private static final Map<String, SqlNode> emptyNodeCache = new ConcurrentHashMap<>();
4343

4444
public XMLScriptBuilder(Configuration configuration, XNode context) {
4545
this(configuration, context, null);
@@ -83,8 +83,7 @@ protected MixedSqlNode parseDynamicTags(XNode node) {
8383
if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) {
8484
String data = child.getStringBody("");
8585
if (data.trim().isEmpty()) {
86-
StaticTextSqlNode staticTextSqlNode = EMPTY_TEXT_NODE.computeIfAbsent(data, StaticTextSqlNode::new);
87-
contents.add(staticTextSqlNode);
86+
contents.add(emptyNodeCache.computeIfAbsent(data, EmptySqlNode::new));
8887
continue;
8988
}
9089
TextSqlNode textSqlNode = new TextSqlNode(data);
@@ -255,4 +254,18 @@ private SqlNode getDefaultSqlNode(List<SqlNode> defaultSqlNodes) {
255254
}
256255
}
257256

257+
private static class EmptySqlNode implements SqlNode {
258+
private final String whitespaces;
259+
260+
public EmptySqlNode(String whitespaces) {
261+
super();
262+
this.whitespaces = whitespaces;
263+
}
264+
265+
@Override
266+
public boolean apply(DynamicContext context) {
267+
context.appendSql(whitespaces);
268+
return true;
269+
}
270+
}
258271
}

0 commit comments

Comments
 (0)