Skip to content

Commit a76a65d

Browse files
authored
Merge pull request #856 from dhoard/text-write-performance-change
Changed to remove use of inefficient String method
2 parents 98967b8 + 27fe3b7 commit a76a65d

File tree

1 file changed

+6
-4
lines changed
  • simpleclient_common/src/main/java/io/prometheus/client/exporter/common

1 file changed

+6
-4
lines changed

simpleclient_common/src/main/java/io/prometheus/client/exporter/common/TextFormat.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ public static void write004(Writer writer, Enumeration<Collector.MetricFamilySam
137137
}
138138

139139
private static void writeEscapedHelp(Writer writer, String s) throws IOException {
140-
for (int i = 0; i < s.length(); i++) {
141-
char c = s.charAt(i);
140+
char[] characters = s.toCharArray();
141+
for (int i = 0; i < characters.length; i++) {
142+
char c = characters[i];
142143
switch (c) {
143144
case '\\':
144145
writer.append("\\\\");
@@ -153,8 +154,9 @@ private static void writeEscapedHelp(Writer writer, String s) throws IOException
153154
}
154155

155156
private static void writeEscapedLabelValue(Writer writer, String s) throws IOException {
156-
for (int i = 0; i < s.length(); i++) {
157-
char c = s.charAt(i);
157+
char[] characters = s.toCharArray();
158+
for (int i = 0; i < characters.length; i++) {
159+
char c = characters[i];
158160
switch (c) {
159161
case '\\':
160162
writer.append("\\\\");

0 commit comments

Comments
 (0)