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

Unified Diff: src/objects.cc

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 side-by-side diff with in-line comments
Download patch
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;
}

Powered by Google App Engine
This is Rietveld 408576698