Skip to content

Commit 80d8457

Browse files
xuwei-kjknack
authored andcommitted
cache the "hbs.buffer" system property in static field (#571)
because `System.getProperty` is slow http://stackoverflow.com/q/18045391
1 parent d976e0a commit 80d8457

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

handlebars/src/main/java/com/github/jknack/handlebars/internal/FastStringWriter.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,26 @@
2929
* @since 0.1.0
3030
*/
3131
class FastStringWriter extends Writer {
32+
33+
/**
34+
* buffer size for StrBuilder.
35+
*/
36+
private static final int BUFFER_SIZE;
37+
38+
static {
39+
int value;
40+
try {
41+
value = Integer.parseInt(System.getProperty("hbs.buffer", "1600"));
42+
} catch (Throwable e) {
43+
value = 1600;
44+
}
45+
BUFFER_SIZE = value;
46+
}
47+
3248
/**
3349
* The internal buffer.
3450
*/
35-
private StrBuilder buffer = new StrBuilder(Integer
36-
.parseInt(System.getProperty("hbs.buffer", "1600")));
51+
private StrBuilder buffer = new StrBuilder(BUFFER_SIZE);
3752

3853
@Override
3954
public Writer append(final char c) throws IOException {

0 commit comments

Comments
 (0)