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

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

Issue 7075009: Double allocation size for special json strings on every resize (fixes (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 7 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 | « src/json-parser.h ('k') | 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 NOT_TENURED); 373 NOT_TENURED);
374 Handle<SeqTwoByteString> seq_two_byte = 374 Handle<SeqTwoByteString> seq_two_byte =
375 Handle<SeqTwoByteString>::cast(two_byte); 375 Handle<SeqTwoByteString>::cast(two_byte);
376 376
377 int allocation_count = 1; 377 int allocation_count = 1;
378 int count = 0; 378 int count = 0;
379 379
380 while (c0_ != '"') { 380 while (c0_ != '"') {
381 // Create new seq string 381 // Create new seq string
382 if (count >= kInitialSpecialStringSize * allocation_count) { 382 if (count >= kInitialSpecialStringSize * allocation_count) {
383 allocation_count++; 383 allocation_count = allocation_count * 2;
384 int new_size = allocation_count * kInitialSpecialStringSize; 384 int new_size = allocation_count * kInitialSpecialStringSize;
385 Handle<String> new_two_byte = 385 Handle<String> new_two_byte =
386 isolate()->factory()->NewRawTwoByteString(new_size, 386 isolate()->factory()->NewRawTwoByteString(new_size,
387 NOT_TENURED); 387 NOT_TENURED);
388 uc16* char_start = 388 uc16* char_start =
389 Handle<SeqTwoByteString>::cast(new_two_byte)->GetChars(); 389 Handle<SeqTwoByteString>::cast(new_two_byte)->GetChars();
390 String::WriteToFlat(*seq_two_byte, char_start, 0, count); 390 String::WriteToFlat(*seq_two_byte, char_start, 0, count);
391 seq_two_byte = Handle<SeqTwoByteString>::cast(new_two_byte); 391 seq_two_byte = Handle<SeqTwoByteString>::cast(new_two_byte);
392 } 392 }
393 393
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 return Token::ILLEGAL; 436 return Token::ILLEGAL;
437 } 437 }
438 Advance(); 438 Advance();
439 } 439 }
440 } 440 }
441 // Advance past the last '"'. 441 // Advance past the last '"'.
442 ASSERT_EQ('"', c0_); 442 ASSERT_EQ('"', c0_);
443 Advance(); 443 Advance();
444 444
445 // Shrink the the string to our length. 445 // Shrink the the string to our length.
446 isolate()->heap()-> 446 if (isolate()->heap()->InNewSpace(*seq_two_byte)) {
447 new_space()-> 447 isolate()->heap()->new_space()->
448 ShrinkStringAtAllocationBoundary<SeqTwoByteString>(*seq_two_byte, 448 ShrinkStringAtAllocationBoundary<SeqTwoByteString>(*seq_two_byte,
449 count); 449 count);
450 } else {
451 int string_size = SeqTwoByteString::SizeFor(count);
452 int allocated_string_size =
453 SeqTwoByteString::SizeFor(kInitialSpecialStringSize * allocation_count);
454 int delta = allocated_string_size - string_size;
455 Address start_filler_object = seq_two_byte->address() + string_size;
456 isolate()->heap()->CreateFillerObjectAt(start_filler_object, delta);
457 }
450 string_val_ = isolate()->factory()->NewConsString(ascii, seq_two_byte); 458 string_val_ = isolate()->factory()->NewConsString(ascii, seq_two_byte);
451 return Token::STRING; 459 return Token::STRING;
452 } 460 }
453 461
454 462
455 Token::Value JsonParser::ScanJsonString() { 463 Token::Value JsonParser::ScanJsonString() {
456 ASSERT_EQ('"', c0_); 464 ASSERT_EQ('"', c0_);
457 // Set string_val to null. If string_val is not set we assume an 465 // Set string_val to null. If string_val is not set we assume an
458 // ascii string begining at next_.beg_pos + 1 to next_.end_pos - 1. 466 // ascii string begining at next_.beg_pos + 1 to next_.end_pos - 1.
459 string_val_ = Handle<String>::null(); 467 string_val_ = Handle<String>::null();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 return isolate()->factory()->LookupAsciiSymbol(seq_source_, 503 return isolate()->factory()->LookupAsciiSymbol(seq_source_,
496 current_.beg_pos + 1, 504 current_.beg_pos + 1,
497 length); 505 length);
498 } 506 }
499 // The current token includes the '"' in both ends. 507 // The current token includes the '"' in both ends.
500 return isolate()->factory()->NewSubString( 508 return isolate()->factory()->NewSubString(
501 source_, current_.beg_pos + 1, current_.end_pos - 1); 509 source_, current_.beg_pos + 1, current_.end_pos - 1);
502 } 510 }
503 511
504 } } // namespace v8::internal 512 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/json-parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698