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

Unified Diff: src/runtime.cc

Issue 5551002: Simplify JSON stringify and add special case for default replacer and space. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 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/json.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
===================================================================
--- src/runtime.cc (revision 5911)
+++ src/runtime.cc (working copy)
@@ -4619,9 +4619,6 @@
quoted_length += JsonQuoteLengths[c];
}
}
- if (quoted_length == length) {
- return Heap::undefined_value();
- }
Counters::quote_json_char_count.Increment(length);
// Add space for quotes.
@@ -4641,17 +4638,22 @@
new_string->address() + SeqAsciiString::kHeaderSize);
*(write_cursor++) = '"';
const Char* read_cursor = characters.start();
- const Char* end = read_cursor + length;
- while (read_cursor < end) {
- Char c = *(read_cursor++);
- if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) {
- *(write_cursor++) = c;
- } else {
- const char* replacement = JsonQuotes[static_cast<unsigned>(c)];
- if (!replacement) {
+ if (quoted_length == length + 2) {
+ CopyChars(write_cursor, read_cursor, length);
+ write_cursor += length;
+ } else {
+ const Char* end = read_cursor + length;
+ while (read_cursor < end) {
+ Char c = *(read_cursor++);
+ if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) {
*(write_cursor++) = c;
} else {
- write_cursor = WriteString(write_cursor, replacement);
+ const char* replacement = JsonQuotes[static_cast<unsigned>(c)];
+ if (!replacement) {
+ *(write_cursor++) = c;
+ } else {
+ write_cursor = WriteString(write_cursor, replacement);
+ }
}
}
}
@@ -4682,6 +4684,7 @@
}
+
static MaybeObject* Runtime_StringParseInt(Arguments args) {
NoHandleAllocation ha;
« no previous file with comments | « src/json.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698