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

Side by Side Diff: base/json/json_writer.h

Issue 2695873002: Prevent some string copies when sending Values to WebUI. (Closed)
Patch Set: Removed another copy Created 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/webui/web_ui_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_JSON_JSON_WRITER_H_ 5 #ifndef BASE_JSON_JSON_WRITER_H_
6 #define BASE_JSON_JSON_WRITER_H_ 6 #define BASE_JSON_JSON_WRITER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 19 matching lines...) Expand all
30 // or appending a '.0') as long as the value is within the range of a 30 // or appending a '.0') as long as the value is within the range of a
31 // 64-bit int. 31 // 64-bit int.
32 OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION = 1 << 1, 32 OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION = 1 << 1,
33 33
34 // Return a slightly nicer formatted json string (pads with whitespace to 34 // Return a slightly nicer formatted json string (pads with whitespace to
35 // help with readability). 35 // help with readability).
36 OPTIONS_PRETTY_PRINT = 1 << 2, 36 OPTIONS_PRETTY_PRINT = 1 << 2,
37 }; 37 };
38 38
39 // Given a root node, generates a JSON string and puts it into |json|. 39 // Given a root node, generates a JSON string and puts it into |json|.
40 // The output string is overwritten and not appended.
41 //
40 // TODO(tc): Should we generate json if it would be invalid json (e.g., 42 // TODO(tc): Should we generate json if it would be invalid json (e.g.,
41 // |node| is not a DictionaryValue/ListValue or if there are inf/-inf float 43 // |node| is not a DictionaryValue/ListValue or if there are inf/-inf float
42 // values)? Return true on success and false on failure. 44 // values)? Return true on success and false on failure.
43 static bool Write(const Value& node, std::string* json); 45 static bool Write(const Value& node, std::string* json);
44 46
45 // Same as above but with |options| which is a bunch of JSONWriter::Options 47 // Same as above but with |options| which is a bunch of JSONWriter::Options
46 // bitwise ORed together. Return true on success and false on failure. 48 // bitwise ORed together. Return true on success and false on failure.
47 static bool WriteWithOptions(const Value& node, 49 static bool WriteWithOptions(const Value& node,
48 int options, 50 int options,
49 std::string* json); 51 std::string* json);
(...skipping 14 matching lines...) Expand all
64 66
65 // Where we write JSON data as we generate it. 67 // Where we write JSON data as we generate it.
66 std::string* json_string_; 68 std::string* json_string_;
67 69
68 DISALLOW_COPY_AND_ASSIGN(JSONWriter); 70 DISALLOW_COPY_AND_ASSIGN(JSONWriter);
69 }; 71 };
70 72
71 } // namespace base 73 } // namespace base
72 74
73 #endif // BASE_JSON_JSON_WRITER_H_ 75 #endif // BASE_JSON_JSON_WRITER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/webui/web_ui_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698