changeset 994:24f2032b147c

generators: cache indent Strings, decreases the allocation pressure.
author shade
date Tue, 02 Sep 2014 23:58:13 +0400
parents a8f5b91bcefc
children 0a0ca0942f1d
files jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Tue Sep 02 23:04:40 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/BenchmarkGenerator.java	Tue Sep 02 23:58:13 2014 +0400
@@ -1059,12 +1059,19 @@
         }
     }
 
-    static String ident(int prefix) {
-        char[] chars = new char[prefix * 4];
-        for (int i = 0; i < prefix * 4; i++) {
-            chars[i] = ' ';
+    static String[] INDENTS = new String[0];
+
+    static String ident(int tabs) {
+        final int TAB_SIZE = 4;
+        if (tabs >= INDENTS.length) {
+            INDENTS = new String[tabs + 1];
+            for (int p = 0; p <= tabs; p++) {
+                char[] chars = new char[p * TAB_SIZE];
+                Arrays.fill(chars, ' ');
+                INDENTS[p] = new String(chars);
+            }
         }
-        return new String(chars);
+        return INDENTS[tabs];
     }
 
 }