Improve escaping performance

This commit is contained in:
Adam Gent
2023-12-19 12:57:38 -05:00
parent a4cd8010a7
commit 96aac1a41f
3 changed files with 125 additions and 1 deletions
@@ -317,6 +317,17 @@ public class Mustache {
default CharSequence escape (CharSequence raw) {
return escape(raw.toString());
}
/**
* Escapes the raw characters with escape sequeneces if needed and appends to the appendable.
* The default implementation calls {@link #escape(CharSequence)}.
* @param a the stream like to append to.
* @param raw input string.
* @throws IOException if an error happens while writing to the appendable.
*/
default void escape (Appendable a, CharSequence raw) throws IOException {
a.append(escape(raw));
}
}
/** Handles loading partial templates. */
@@ -1317,7 +1328,7 @@ public class Mustache {
"No key, method or field with name '" + _name + "' on line " + _line;
throw new MustacheException.Context(msg, _name, _line);
}
write(out, _escaper.escape(_formatter.format(value)));
escape(out, _formatter.format(value), _escaper);
}
@Override public void decompile (Delims delims, StringBuilder into) {
delims.addTag(' ', _name, into);