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

Side by Side Diff: src/json-parser.h

Issue 11184006: Eagerly follow transitions to existing maps while json parsing. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/objects.h » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 return ParseJsonArray(); 282 return ParseJsonArray();
283 default: 283 default:
284 return ReportUnexpectedCharacter(); 284 return ReportUnexpectedCharacter();
285 } 285 }
286 } 286 }
287 287
288 288
289 // Parse a JSON object. Position must be right at '{'. 289 // Parse a JSON object. Position must be right at '{'.
290 template <bool seq_ascii> 290 template <bool seq_ascii>
291 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { 291 Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() {
292 int current_index = 0;
293 Handle<Object> prototype;
292 Handle<JSFunction> object_constructor( 294 Handle<JSFunction> object_constructor(
293 isolate()->native_context()->object_function()); 295 isolate()->native_context()->object_function());
294 Handle<JSObject> json_object = 296 Handle<JSObject> json_object =
295 isolate()->factory()->NewJSObject(object_constructor); 297 isolate()->factory()->NewJSObject(object_constructor);
296 ASSERT_EQ(c0_, '{'); 298 ASSERT_EQ(c0_, '{');
297 299
298 AdvanceSkipWhitespace(); 300 AdvanceSkipWhitespace();
299 if (c0_ != '}') { 301 if (c0_ != '}') {
300 do { 302 do {
301 if (c0_ != '"') return ReportUnexpectedCharacter(); 303 if (c0_ != '"') return ReportUnexpectedCharacter();
302 Handle<String> key = ParseJsonSymbol(); 304 Handle<String> key = ParseJsonSymbol();
303 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter(); 305 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter();
304 AdvanceSkipWhitespace(); 306 AdvanceSkipWhitespace();
305 Handle<Object> value = ParseJsonValue(); 307 Handle<Object> value = ParseJsonValue();
306 if (value.is_null()) return ReportUnexpectedCharacter(); 308 if (value.is_null()) return ReportUnexpectedCharacter();
307 309
308 uint32_t index; 310 uint32_t index;
309 if (key->AsArrayIndex(&index)) { 311 if (key->AsArrayIndex(&index)) {
310 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode); 312 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode);
311 } else if (key->Equals(isolate()->heap()->Proto_symbol())) { 313 } else if (key->Equals(isolate()->heap()->Proto_symbol())) {
312 SetPrototype(json_object, value); 314 prototype = value;
313 } else { 315 } else {
314 JSObject::SetLocalPropertyIgnoreAttributes( 316 if (JSObject::TryTransitionToField(json_object, key)) {
315 json_object, key, value, NONE); 317 json_object->FastPropertyAtPut(current_index++, *value);
318 } else {
319 JSObject::SetLocalPropertyIgnoreAttributes(
320 json_object, key, value, NONE);
321 }
316 } 322 }
317 } while (MatchSkipWhiteSpace(',')); 323 } while (MatchSkipWhiteSpace(','));
318 if (c0_ != '}') { 324 if (c0_ != '}') {
319 return ReportUnexpectedCharacter(); 325 return ReportUnexpectedCharacter();
320 } 326 }
327 if (!prototype.is_null()) SetPrototype(json_object, prototype);
321 } 328 }
322 AdvanceSkipWhitespace(); 329 AdvanceSkipWhitespace();
323 return json_object; 330 return json_object;
324 } 331 }
325 332
326 // Parse a JSON array. Position must be right at '['. 333 // Parse a JSON array. Position must be right at '['.
327 template <bool seq_ascii> 334 template <bool seq_ascii>
328 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() { 335 Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() {
329 ZoneScope zone_scope(zone(), DELETE_ON_EXIT); 336 ZoneScope zone_scope(zone(), DELETE_ON_EXIT);
330 ZoneList<Handle<Object> > elements(4, zone()); 337 ZoneList<Handle<Object> > elements(4, zone());
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } 649 }
643 ASSERT_EQ('"', c0_); 650 ASSERT_EQ('"', c0_);
644 // Advance past the last '"'. 651 // Advance past the last '"'.
645 AdvanceSkipWhitespace(); 652 AdvanceSkipWhitespace();
646 return result; 653 return result;
647 } 654 }
648 655
649 } } // namespace v8::internal 656 } } // namespace v8::internal
650 657
651 #endif // V8_JSON_PARSER_H_ 658 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698