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

Side by Side 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: Make it look exactly the same as ComputeArrayIndex 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 | no next file » | 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 Handle<JSFunction> object_constructor( 294 Handle<JSFunction> object_constructor(
295 isolate()->native_context()->object_function()); 295 isolate()->native_context()->object_function());
296 Handle<JSObject> json_object = 296 Handle<JSObject> json_object =
297 isolate()->factory()->NewJSObject(object_constructor); 297 isolate()->factory()->NewJSObject(object_constructor);
298 ASSERT_EQ(c0_, '{'); 298 ASSERT_EQ(c0_, '{');
299 299
300 AdvanceSkipWhitespace(); 300 AdvanceSkipWhitespace();
301 if (c0_ != '}') { 301 if (c0_ != '}') {
302 do { 302 do {
303 if (c0_ != '"') return ReportUnexpectedCharacter(); 303 if (c0_ != '"') return ReportUnexpectedCharacter();
304 Handle<String> key = ParseJsonSymbol();
305 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter();
306 AdvanceSkipWhitespace();
307 Handle<Object> value = ParseJsonValue();
308 if (value.is_null()) return ReportUnexpectedCharacter();
309 304
310 uint32_t index; 305 int start_position = position_;
311 if (key->AsArrayIndex(&index)) { 306 Advance();
307
308 uint32_t index = 0;
309 while (c0_ >= '0' && c0_ <= '9') {
310 int d = c0_ - '0';
311 if (index > 429496729U - ((d > 5) ? 1 : 0)) break;
312 index = (index * 10) + d;
313 Advance();
314 }
315
316 if (position_ != start_position + 1 && c0_ == '"') {
317 AdvanceSkipWhitespace();
318
319 if (c0_ != ':') return ReportUnexpectedCharacter();
320 AdvanceSkipWhitespace();
321 Handle<Object> value = ParseJsonValue();
322 if (value.is_null()) return ReportUnexpectedCharacter();
323
312 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode); 324 JSObject::SetOwnElement(json_object, index, value, kNonStrictMode);
313 } else if (key->Equals(isolate()->heap()->Proto_symbol())) {
314 prototype = value;
315 } else { 325 } else {
316 if (JSObject::TryTransitionToField(json_object, key)) { 326 position_ = start_position;
317 json_object->FastPropertyAtPut(current_index++, *value); 327 #ifdef DEBUG
328 c0_ = '"';
329 #endif
330
331 Handle<String> key = ParseJsonSymbol();
332 if (key.is_null() || c0_ != ':') return ReportUnexpectedCharacter();
333
334 AdvanceSkipWhitespace();
335 Handle<Object> value = ParseJsonValue();
336 if (value.is_null()) return ReportUnexpectedCharacter();
337
338 if (key->Equals(isolate()->heap()->Proto_symbol())) {
339 prototype = value;
318 } else { 340 } else {
319 JSObject::SetLocalPropertyIgnoreAttributes( 341 if (JSObject::TryTransitionToField(json_object, key)) {
320 json_object, key, value, NONE); 342 json_object->FastPropertyAtPut(current_index++, *value);
343 } else {
344 JSObject::SetLocalPropertyIgnoreAttributes(
345 json_object, key, value, NONE);
346 }
321 } 347 }
322 } 348 }
323 } while (MatchSkipWhiteSpace(',')); 349 } while (MatchSkipWhiteSpace(','));
324 if (c0_ != '}') { 350 if (c0_ != '}') {
325 return ReportUnexpectedCharacter(); 351 return ReportUnexpectedCharacter();
326 } 352 }
327 if (!prototype.is_null()) SetPrototype(json_object, prototype); 353 if (!prototype.is_null()) SetPrototype(json_object, prototype);
328 } 354 }
329 AdvanceSkipWhitespace(); 355 AdvanceSkipWhitespace();
330 return json_object; 356 return json_object;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 Advance(); 393 Advance();
368 negative = true; 394 negative = true;
369 } 395 }
370 if (c0_ == '0') { 396 if (c0_ == '0') {
371 Advance(); 397 Advance();
372 // Prefix zero is only allowed if it's the only digit before 398 // Prefix zero is only allowed if it's the only digit before
373 // a decimal point or exponent. 399 // a decimal point or exponent.
374 if ('0' <= c0_ && c0_ <= '9') return ReportUnexpectedCharacter(); 400 if ('0' <= c0_ && c0_ <= '9') return ReportUnexpectedCharacter();
375 } else { 401 } else {
376 int i = 0; 402 int i = 0;
377 int digits = 0;
378 if (c0_ < '1' || c0_ > '9') return ReportUnexpectedCharacter(); 403 if (c0_ < '1' || c0_ > '9') return ReportUnexpectedCharacter();
379 do { 404 do {
380 i = i * 10 + c0_ - '0'; 405 i = i * 10 + c0_ - '0';
381 digits++;
382 Advance(); 406 Advance();
383 } while (c0_ >= '0' && c0_ <= '9'); 407 } while (c0_ >= '0' && c0_ <= '9' && i <= (kMaxInt - 9) / 10);
384 if (c0_ != '.' && c0_ != 'e' && c0_ != 'E' && digits < 10) { 408 if (c0_ != '.' && c0_ != 'e' && c0_ != 'E') {
385 SkipWhitespace(); 409 SkipWhitespace();
386 return Handle<Smi>(Smi::FromInt((negative ? -i : i)), isolate()); 410 return Handle<Smi>(Smi::FromInt((negative ? -i : i)), isolate());
387 } 411 }
388 } 412 }
389 if (c0_ == '.') { 413 if (c0_ == '.') {
390 Advance(); 414 Advance();
391 if (c0_ < '0' || c0_ > '9') return ReportUnexpectedCharacter(); 415 if (c0_ < '0' || c0_ > '9') return ReportUnexpectedCharacter();
392 do { 416 do {
393 Advance(); 417 Advance();
394 } while (c0_ >= '0' && c0_ <= '9'); 418 } while (c0_ >= '0' && c0_ <= '9');
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 673 }
650 ASSERT_EQ('"', c0_); 674 ASSERT_EQ('"', c0_);
651 // Advance past the last '"'. 675 // Advance past the last '"'.
652 AdvanceSkipWhitespace(); 676 AdvanceSkipWhitespace();
653 return result; 677 return result;
654 } 678 }
655 679
656 } } // namespace v8::internal 680 } } // namespace v8::internal
657 681
658 #endif // V8_JSON_PARSER_H_ 682 #endif // V8_JSON_PARSER_H_
OLDNEW
« 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