Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index dbbec582228aad3e6d7b610d2a51d44205461ab9..5b70c98f28f77b55dd80579af00eeeefc7c63a30 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -7626,33 +7626,42 @@ bool String::SlowAsArrayIndex(uint32_t* index) { |
} |
-String* SeqString::Truncate(int new_length) { |
- Heap* heap = GetHeap(); |
- if (new_length <= 0) return heap->empty_string(); |
+void SeqString::Truncate(int new_length) { |
+ ASSERT_LT(0, new_length); |
Hannes Payer (out of office)
2013/03/21 12:48:30
new_length = 0 should be possible
|
- int string_size, allocated_string_size; |
+ int new_size, old_size; |
int old_length = length(); |
- if (old_length <= new_length) return this; |
+ if (old_length <= new_length) return; |
if (IsSeqOneByteString()) { |
- allocated_string_size = SeqOneByteString::SizeFor(old_length); |
- string_size = SeqOneByteString::SizeFor(new_length); |
+ old_size = SeqOneByteString::SizeFor(old_length); |
+ new_size = SeqOneByteString::SizeFor(new_length); |
} else { |
- allocated_string_size = SeqTwoByteString::SizeFor(old_length); |
- string_size = SeqTwoByteString::SizeFor(new_length); |
+ old_size = SeqTwoByteString::SizeFor(old_length); |
+ new_size = SeqTwoByteString::SizeFor(new_length); |
} |
- int delta = allocated_string_size - string_size; |
+ int delta = old_size - new_size; |
set_length(new_length); |
- // String sizes are pointer size aligned, so that we can use filler objects |
- // that are a multiple of pointer size. |
- Address end_of_string = address() + string_size; |
- heap->CreateFillerObjectAt(end_of_string, delta); |
+ Address start_of_string = address(); |
+ ASSERT_OBJECT_ALIGNED(start_of_string); |
+ ASSERT_OBJECT_ALIGNED(start_of_string + new_size); |
+ |
+ Heap* heap = GetHeap(); |
+ if (heap->InNewSpace(start_of_string) && |
+ heap->new_space()->allocation_info_.top == start_of_string + old_size) { |
+ // Last allocated object in new space. Simply lower allocation top. |
+ heap->new_space()->allocation_info_.top = start_of_string + new_size; |
Hannes Payer (out of office)
2013/03/21 12:48:30
I think you also want to adjust MemoryChunk::Incre
Yang
2013/03/21 14:18:34
I'm doing this summarily below.
|
+ } else { |
+ // String sizes are pointer size aligned, so that we can use filler objects |
+ // that are a multiple of pointer size. |
+ heap->CreateFillerObjectAt(start_of_string + new_size, delta); |
Hannes Payer (out of office)
2013/03/21 12:48:30
Do we also have to adjust MemoryChunk::IncrementL
Yang
2013/03/21 14:18:34
I'm doing this summarily below.
|
+ } |
+ |
if (Marking::IsBlack(Marking::MarkBitFrom(this))) { |
- MemoryChunk::IncrementLiveBytesFromMutator(address(), -delta); |
+ MemoryChunk::IncrementLiveBytesFromMutator(start_of_string, -delta); |
} |
- return this; |
} |