Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: src/tracing/traced-value.cc

Issue 2555043003: [tracing] Make TracedValue accept const char* strings (Closed)
Patch Set: Rebaseline Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/tracing/traced-value.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/tracing/traced-value.cc
diff --git a/src/tracing/traced-value.cc b/src/tracing/traced-value.cc
index 3406bbf6fe71bfbbb16e53471abda711eeeb99ec..58d0f5d5bac9dfb016697e62032cc3d6003b6dd1 100644
--- a/src/tracing/traced-value.cc
+++ b/src/tracing/traced-value.cc
@@ -23,40 +23,36 @@ const bool kStackTypeArray = true;
#define DEBUG_POP_CONTAINER() ((void)0)
#endif
-std::string EscapeString(const std::string& value) {
- std::string result;
- result.reserve(value.length() + 2);
- result += '"';
- size_t length = value.length();
+void EscapeAndAppendString(const char* value, std::string* result) {
+ *result += '"';
char number_buffer[10];
- for (size_t src = 0; src < length; ++src) {
- char c = value[src];
+ while (*value) {
+ char c = *value++;
switch (c) {
case '\t':
- result += "\\t";
+ *result += "\\t";
break;
case '\n':
- result += "\\n";
+ *result += "\\n";
break;
case '\"':
- result += "\\\"";
+ *result += "\\\"";
break;
case '\\':
- result += "\\\\";
+ *result += "\\\\";
break;
default:
if (c < '\040') {
base::OS::SNPrintF(
number_buffer, arraysize(number_buffer), "\\u%04X",
static_cast<unsigned>(static_cast<unsigned char>(c)));
- result += number_buffer;
+ *result += number_buffer;
} else {
- result += c;
+ *result += c;
}
}
}
- result += '"';
- return result;
+ *result += '"';
}
} // namespace
@@ -93,10 +89,10 @@ void TracedValue::SetBoolean(const char* name, bool value) {
data_ += value ? "true" : "false";
}
-void TracedValue::SetString(const char* name, const std::string& value) {
+void TracedValue::SetString(const char* name, const char* value) {
DCHECK_CURRENT_CONTAINER_IS(kStackTypeDict);
WriteName(name);
- data_ += EscapeString(value);
+ EscapeAndAppendString(value, &data_);
}
void TracedValue::BeginDictionary(const char* name) {
@@ -133,10 +129,10 @@ void TracedValue::AppendBoolean(bool value) {
data_ += value ? "true" : "false";
}
-void TracedValue::AppendString(const std::string& value) {
+void TracedValue::AppendString(const char* value) {
DCHECK_CURRENT_CONTAINER_IS(kStackTypeArray);
WriteComma();
- data_ += EscapeString(value);
+ EscapeAndAppendString(value, &data_);
}
void TracedValue::BeginDictionary() {
« no previous file with comments | « src/tracing/traced-value.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698