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

Unified Diff: src/json-parser.h

Issue 11189039: Adding a fast path for parsing index keys. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: u Created 8 years, 2 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/json-parser.h
diff --git a/src/json-parser.h b/src/json-parser.h
index 0b8cb769ca679676b85b3dd8884500a480f23800..5adc57664986bf275379a6fb4de8951824084bea 100644
--- a/src/json-parser.h
+++ b/src/json-parser.h
@@ -301,23 +301,52 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() {
if (c0_ != '}') {
do {
if (c0_ != '"') return ReportUnexpectedCharacter();
- Handle<String> key = ParseJsonSymbol();
- if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter();
- AdvanceSkipWhitespace();
- Handle<Object> value = ParseJsonValue();
- if (value.is_null()) return ReportUnexpectedCharacter();
- uint32_t index;
- if (key->AsArrayIndex(&index)) {
+ int position = position_;
Yang 2012/10/18 13:45:32 maybe something more descriptive than "position",
Toon Verwaest 2012/10/18 14:15:26 Done.
+ Advance();
+
+ int digits = 0;
+ uint32_t index = 0;
+ while (c0_ >= '0' && c0_ <= '9') {
+ index = index * 10 + c0_ - '0';
+ digits++;
+ Advance();
+ }
+
+ if (digits > 0 && c0_ == '"' && digits < 10) {
Yang 2012/10/18 13:45:32 Why 10? The logic of calculating array index (in S
+ AdvanceSkipWhitespace();
+
+ if (c0_ != ':') return ReportUnexpectedCharacter();
+ AdvanceSkipWhitespace();
+ Handle<Object> value = ParseJsonValue();
+ if (value.is_null()) return ReportUnexpectedCharacter();
+
JSObject::SetOwnElement(json_object, index, value, kNonStrictMode);
- } else if (key->Equals(isolate()->heap()->Proto_symbol())) {
- prototype = value;
} else {
- if (JSObject::TryTransitionToField(json_object, key)) {
- json_object->FastPropertyAtPut(current_index++, *value);
+ position_ = position;
+#ifdef DEBUG
+ c0_ = '"';
+#endif
+
+ Handle<String> key = ParseJsonSymbol();
+ if (key.is_null()) return ReportUnexpectedCharacter();
Yang 2012/10/18 13:45:32 Keeping it as if (key.is_null() || c0_ != ':') ret
Toon Verwaest 2012/10/18 14:15:26 Done.
+
+ if (c0_ != ':') return ReportUnexpectedCharacter();
+ AdvanceSkipWhitespace();
+ Handle<Object> value = ParseJsonValue();
+ if (value.is_null()) return ReportUnexpectedCharacter();
+
+ if (key->AsArrayIndex(&index)) {
+ JSObject::SetOwnElement(json_object, index, value, kNonStrictMode);
+ } else if (key->Equals(isolate()->heap()->Proto_symbol())) {
+ prototype = value;
} else {
- JSObject::SetLocalPropertyIgnoreAttributes(
- json_object, key, value, NONE);
+ if (JSObject::TryTransitionToField(json_object, key)) {
+ json_object->FastPropertyAtPut(current_index++, *value);
+ } else {
+ JSObject::SetLocalPropertyIgnoreAttributes(
+ json_object, key, value, NONE);
+ }
}
}
} while (MatchSkipWhiteSpace(','));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698