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

Unified Diff: src/json.js

Issue 6335004: Optimize JSON stringify by allowing QuoteJSONString to prefix with a comma. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 11 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 | « no previous file | src/runtime.h » ('j') | src/runtime.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json.js
===================================================================
--- src/json.js (revision 6322)
+++ src/json.js (working copy)
@@ -193,14 +193,14 @@
// First entry is a string. Remaining entries are likely to be strings too.
builder.push(%QuoteJSONString(val));
for (var i = 1; i < len; i++) {
- builder.push(",");
val = value[i];
if (IS_STRING(val)) {
- builder.push(%QuoteJSONString(val));
+ builder.push(%QuoteJSONStringComma(val));
} else {
+ builder.push(",");
var before = builder.length;
BasicJSONSerialize(i, value[i], stack, builder);
- if (before == builder.length) builder.push("null");
+ if (before == builder.length) builder[before - 1] = ",null";
}
}
} else if (IS_NUMBER(val)) {
@@ -216,7 +216,7 @@
} else {
var before = builder.length;
BasicJSONSerialize(i, value[i], stack, builder);
- if (before == builder.length) builder.push("null");
+ if (before == builder.length) builder[before - 1] = ",null";
}
}
} else {
@@ -228,7 +228,7 @@
before = builder.length;
val = value[i];
BasicJSONSerialize(i, val, stack, builder);
- if (before == builder.length) builder.push("null");
+ if (before == builder.length) builder[before - 1] = ",null";
}
}
stack.pop();
@@ -241,9 +241,11 @@
throw MakeTypeError('circular_structure', []);
}
builder.push("{");
+ var not_first = false;
Erik Corry 2011/01/14 14:42:57 This variable should be called first and the boole
sandholm 2011/01/16 21:08:43 Done.
for (var p in value) {
if (%HasLocalProperty(value, p)) {
- builder.push(%QuoteJSONString(p));
+ if (not_first) builder.push(%QuoteJSONStringComma(p));
Erik Corry 2011/01/14 14:42:57 multi-line if statements should use {}
sandholm 2011/01/16 21:08:43 Done.
+ else builder.push(%QuoteJSONString(p));
builder.push(":");
var before = builder.length;
BasicJSONSerialize(p, value[p], stack, builder);
@@ -251,16 +253,12 @@
builder.pop();
builder.pop();
} else {
- builder.push(",");
+ not_first = true;
}
}
}
stack.pop();
- if (builder.pop() != ",") {
- builder.push("{}"); // Object has no own properties. Push "{" back on.
- } else {
- builder.push("}");
- }
+ builder.push("}");
}
« no previous file with comments | « no previous file | src/runtime.h » ('j') | src/runtime.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698