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

Unified Diff: src/objects.cc

Issue 11348349: Improve array to string conversion. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years 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 324b10ce2066c5fc0c24fd485813f895557b089c..86b7e844ec0681068b85720cd4291a165f8d6401 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -7622,6 +7622,30 @@ bool String::SlowAsArrayIndex(uint32_t* index) {
}
+void SeqString::Truncate(int new_length) {
+ int string_size, allocated_string_size;
+ ASSERT(new_length < length() && new_length > 0);
+ if (IsSeqOneByteString()) {
+ allocated_string_size = SeqOneByteString::SizeFor(length());
+ string_size = SeqOneByteString::SizeFor(new_length);
+ } else {
+ allocated_string_size = SeqTwoByteString::SizeFor(length());
+ string_size = SeqTwoByteString::SizeFor(new_length);
+ }
+
+ int delta = allocated_string_size - string_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;
+ GetHeap()->CreateFillerObjectAt(end_of_string, delta);
+ if (Marking::IsBlack(Marking::MarkBitFrom(this))) {
+ MemoryChunk::IncrementLiveBytesFromMutator(address(), -delta);
+ }
+}
+
+
uint32_t StringHasher::MakeArrayIndexHash(uint32_t value, int length) {
// For array indexes mix the length into the hash as an array index could
// be zero.

Powered by Google App Engine
This is Rietveld 408576698