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

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

Issue 12440061: Improve SeqString::Truncate for latest allocated strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 9 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 Handle<String> string, 315 Handle<String> string,
316 Handle<String> result) { 316 Handle<String> result) {
317 AssertNoAllocation no_allocation; 317 AssertNoAllocation no_allocation;
318 int final_size = 0; 318 int final_size = 0;
319 StringType* dest = StringType::cast(*result); 319 StringType* dest = StringType::cast(*result);
320 dest->Set(final_size++, '\"'); 320 dest->Set(final_size++, '\"');
321 final_size += SerializeStringUnchecked_(StringType::cast(*string)->GetChars(), 321 final_size += SerializeStringUnchecked_(StringType::cast(*string)->GetChars(),
322 dest->GetChars() + 1, 322 dest->GetChars() + 1,
323 string->length()); 323 string->length());
324 dest->Set(final_size++, '\"'); 324 dest->Set(final_size++, '\"');
325 if (isolate->heap()->InNewSpace(*result)) { 325 SeqString::cast(*result)->Truncate(final_size);
326 // In new space, simply lower the allocation top to fit the actual size. 326 return *result;
327 isolate->heap()->new_space()->ShrinkStringAtAllocationBoundary<StringType>(
328 *result, final_size);
329 return *result;
330 } else {
331 // Not in new space, need to fill the wasted space with filler objects.
332 return SeqString::cast(*result)->Truncate(final_size);
333 }
334 } 327 }
335 328
336 329
337 template <bool is_ascii, typename Char> 330 template <bool is_ascii, typename Char>
338 void BasicJsonStringifier::Append_(Char c) { 331 void BasicJsonStringifier::Append_(Char c) {
339 if (is_ascii) { 332 if (is_ascii) {
340 SeqOneByteString::cast(*current_part_)->SeqOneByteStringSet( 333 SeqOneByteString::cast(*current_part_)->SeqOneByteStringSet(
341 current_index_++, c); 334 current_index_++, c);
342 } else { 335 } else {
343 SeqTwoByteString::cast(*current_part_)->SeqTwoByteStringSet( 336 SeqTwoByteString::cast(*current_part_)->SeqTwoByteStringSet(
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 683
691 Append('}'); 684 Append('}');
692 StackPop(); 685 StackPop();
693 current_part_ = handle_scope.CloseAndEscape(current_part_); 686 current_part_ = handle_scope.CloseAndEscape(current_part_);
694 return SUCCESS; 687 return SUCCESS;
695 } 688 }
696 689
697 690
698 void BasicJsonStringifier::ShrinkCurrentPart() { 691 void BasicJsonStringifier::ShrinkCurrentPart() {
699 ASSERT(current_index_ < part_length_); 692 ASSERT(current_index_ < part_length_);
700 current_part_ = Handle<String>( 693 if (current_index_ == 0) {
Hannes Payer (out of office) 2013/03/21 12:48:30 Again, Truncate() should do the right thing for yo
701 SeqString::cast(*current_part_)->Truncate(current_index_), isolate_); 694 current_part_ = isolate_->factory()->empty_string();
695 } else {
696 SeqString::cast(*current_part_)->Truncate(current_index_);
697 }
702 } 698 }
703 699
704 700
705 void BasicJsonStringifier::Extend() { 701 void BasicJsonStringifier::Extend() {
706 set_accumulator(factory_->NewConsString(accumulator(), current_part_)); 702 set_accumulator(factory_->NewConsString(accumulator(), current_part_));
707 if (part_length_ <= kMaxPartLength / kPartLengthGrowthFactor) { 703 if (part_length_ <= kMaxPartLength / kPartLengthGrowthFactor) {
708 part_length_ *= kPartLengthGrowthFactor; 704 part_length_ *= kPartLengthGrowthFactor;
709 } 705 }
710 if (is_ascii_) { 706 if (is_ascii_) {
711 current_part_ = factory_->NewRawOneByteString(part_length_); 707 current_part_ = factory_->NewRawOneByteString(part_length_);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 SerializeString_<false, uint8_t>(object); 836 SerializeString_<false, uint8_t>(object);
841 } else { 837 } else {
842 SerializeString_<false, uc16>(object); 838 SerializeString_<false, uc16>(object);
843 } 839 }
844 } 840 }
845 } 841 }
846 842
847 } } // namespace v8::internal 843 } } // namespace v8::internal
848 844
849 #endif // V8_JSON_STRINGIFIER_H_ 845 #endif // V8_JSON_STRINGIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698