aboutsummaryrefslogtreecommitdiff
path: root/src/univalue
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-09-05 13:10:39 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-09-05 14:42:22 +0200
commit41ef558aa907c50a055c44c4e6abaf813b23aeff (patch)
tree8aa5e375080fa536c9fce57ba2b37058d3f9fb53 /src/univalue
parent406f18cfc443f1c7d520e17a8a0cb43ace6b32cc (diff)
downloadbitcoin-41ef558aa907c50a055c44c4e6abaf813b23aeff.tar.xz
univalue: make spaceStr thread-safe
Simply add spaces to the existing string instead of using a temporary. Fixes #4756.
Diffstat (limited to 'src/univalue')
-rw-r--r--src/univalue/univalue_write.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/univalue/univalue_write.cpp b/src/univalue/univalue_write.cpp
index 042091a827..9565cfa11a 100644
--- a/src/univalue/univalue_write.cpp
+++ b/src/univalue/univalue_write.cpp
@@ -70,15 +70,9 @@ string UniValue::write(unsigned int prettyIndent,
return s;
}
-static string spaceStr;
-
-static string indentStr(unsigned int prettyIndent, unsigned int indentLevel)
+static void indentStr(unsigned int prettyIndent, unsigned int indentLevel, string& s)
{
- unsigned int spaces = prettyIndent * indentLevel;
- while (spaceStr.size() < spaces)
- spaceStr += " ";
-
- return spaceStr.substr(0, spaces);
+ s.append(prettyIndent * indentLevel, ' ');
}
void UniValue::writeArray(unsigned int prettyIndent, unsigned int indentLevel, string& s) const
@@ -89,7 +83,7 @@ void UniValue::writeArray(unsigned int prettyIndent, unsigned int indentLevel, s
for (unsigned int i = 0; i < values.size(); i++) {
if (prettyIndent)
- s += indentStr(prettyIndent, indentLevel);
+ indentStr(prettyIndent, indentLevel, s);
s += values[i].write(prettyIndent, indentLevel + 1);
if (i != (values.size() - 1)) {
s += ",";
@@ -101,7 +95,7 @@ void UniValue::writeArray(unsigned int prettyIndent, unsigned int indentLevel, s
}
if (prettyIndent)
- s += indentStr(prettyIndent, indentLevel - 1);
+ indentStr(prettyIndent, indentLevel - 1, s);
s += "]";
}
@@ -113,7 +107,7 @@ void UniValue::writeObject(unsigned int prettyIndent, unsigned int indentLevel,
for (unsigned int i = 0; i < keys.size(); i++) {
if (prettyIndent)
- s += indentStr(prettyIndent, indentLevel);
+ indentStr(prettyIndent, indentLevel, s);
s += "\"" + json_escape(keys[i]) + "\":";
if (prettyIndent)
s += " ";
@@ -125,7 +119,7 @@ void UniValue::writeObject(unsigned int prettyIndent, unsigned int indentLevel,
}
if (prettyIndent)
- s += indentStr(prettyIndent, indentLevel - 1);
+ indentStr(prettyIndent, indentLevel - 1, s);
s += "}";
}