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

Unified Diff: base/json/json_string_value_serializer.cc

Issue 895913004: JSONStringValueSerializer takes a StringPiece instead of std::string&. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@json-nullstring
Patch Set: Created 5 years, 10 months 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 | « base/json/json_string_value_serializer.h ('k') | base/json/json_value_serializer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/json_string_value_serializer.cc
diff --git a/base/json/json_string_value_serializer.cc b/base/json/json_string_value_serializer.cc
index b48f73c34269fa95a173c332ad1d71464a80303f..b626640a1bfc646b15f09e4c548045ea0758266e 100644
--- a/base/json/json_string_value_serializer.cc
+++ b/base/json/json_string_value_serializer.cc
@@ -12,16 +12,15 @@ using base::Value;
JSONStringValueSerializer::JSONStringValueSerializer(std::string* json_string)
: json_string_(json_string),
- initialized_with_const_string_(false),
+ json_string_readonly_(*json_string),
pretty_print_(false),
allow_trailing_comma_(false) {
- DCHECK(json_string);
}
JSONStringValueSerializer::JSONStringValueSerializer(
- const std::string& json_string)
- : json_string_(&const_cast<std::string&>(json_string)),
- initialized_with_const_string_(true),
+ const base::StringPiece& json_string)
+ : json_string_(nullptr),
+ json_string_readonly_(json_string),
pretty_print_(false),
allow_trailing_comma_(false) {
}
@@ -39,7 +38,7 @@ bool JSONStringValueSerializer::SerializeAndOmitBinaryValues(
bool JSONStringValueSerializer::SerializeInternal(const Value& root,
bool omit_binary_values) {
- if (initialized_with_const_string_)
+ if (!json_string_)
return false;
int options = 0;
@@ -53,7 +52,7 @@ bool JSONStringValueSerializer::SerializeInternal(const Value& root,
Value* JSONStringValueSerializer::Deserialize(int* error_code,
std::string* error_str) {
- return base::JSONReader::ReadAndReturnError(*json_string_,
+ return base::JSONReader::ReadAndReturnError(json_string_readonly_,
allow_trailing_comma_ ? base::JSON_ALLOW_TRAILING_COMMAS :
base::JSON_PARSE_RFC,
error_code, error_str);
« no previous file with comments | « base/json/json_string_value_serializer.h ('k') | base/json/json_value_serializer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698