Index: src/objects.cc |
diff --git a/src/objects.cc b/src/objects.cc |
index c8acb4707181a7c7f8ab1ad7e2a32d92ef4eb8e1..360eb28fb1679aea0ca9abc9027fd0091d90598c 100644 |
--- a/src/objects.cc |
+++ b/src/objects.cc |
@@ -631,7 +631,7 @@ Object* String::SlowTryFlatten(PretenureFlag pretenure) { |
case kConsStringTag: { |
ConsString* cs = ConsString::cast(this); |
if (cs->second()->length() == 0) { |
- return this; |
+ return cs->first(); |
} |
// There's little point in putting the flat string in new space if the |
// cons string is in old space. It can never get GCed until there is |
@@ -669,7 +669,7 @@ Object* String::SlowTryFlatten(PretenureFlag pretenure) { |
} |
cs->set_first(result); |
cs->set_second(Heap::empty_string()); |
- return this; |
+ return result; |
} |
default: |
return this; |
@@ -4580,51 +4580,58 @@ bool String::SlowEquals(String* other) { |
if (Hash() != other->Hash()) return false; |
} |
- if (StringShape(this).IsSequentialAscii() && |
- StringShape(other).IsSequentialAscii()) { |
- const char* str1 = SeqAsciiString::cast(this)->GetChars(); |
- const char* str2 = SeqAsciiString::cast(other)->GetChars(); |
+ // We know the strings are both non-empty. Compare the first chars |
+ // before we try to flatten the strings. |
+ if (this->Get(0) != other->Get(0)) return false; |
+ |
+ String* lhs = this->TryFlattenGetString(); |
+ String* rhs = other->TryFlattenGetString(); |
+ |
+ if (StringShape(lhs).IsSequentialAscii() && |
Mads Ager (chromium)
2010/05/19 12:27:43
lhs->IsSeqAsciiString() and rhs->IsSeqAsciiString(
|
+ StringShape(rhs).IsSequentialAscii()) { |
+ const char* str1 = SeqAsciiString::cast(lhs)->GetChars(); |
+ const char* str2 = SeqAsciiString::cast(rhs)->GetChars(); |
return CompareRawStringContents(Vector<const char>(str1, len), |
Vector<const char>(str2, len)); |
} |
- if (this->IsFlat()) { |
+ if (lhs->IsFlat()) { |
if (IsAsciiRepresentation()) { |
- Vector<const char> vec1 = this->ToAsciiVector(); |
- if (other->IsFlat()) { |
- if (other->IsAsciiRepresentation()) { |
- Vector<const char> vec2 = other->ToAsciiVector(); |
+ Vector<const char> vec1 = lhs->ToAsciiVector(); |
+ if (rhs->IsFlat()) { |
+ if (rhs->IsAsciiRepresentation()) { |
+ Vector<const char> vec2 = rhs->ToAsciiVector(); |
return CompareRawStringContents(vec1, vec2); |
} else { |
VectorIterator<char> buf1(vec1); |
- VectorIterator<uc16> ib(other->ToUC16Vector()); |
+ VectorIterator<uc16> ib(rhs->ToUC16Vector()); |
return CompareStringContents(&buf1, &ib); |
} |
} else { |
VectorIterator<char> buf1(vec1); |
- string_compare_buffer_b.Reset(0, other); |
+ string_compare_buffer_b.Reset(0, rhs); |
return CompareStringContents(&buf1, &string_compare_buffer_b); |
} |
} else { |
- Vector<const uc16> vec1 = this->ToUC16Vector(); |
- if (other->IsFlat()) { |
- if (other->IsAsciiRepresentation()) { |
+ Vector<const uc16> vec1 = lhs->ToUC16Vector(); |
+ if (rhs->IsFlat()) { |
+ if (rhs->IsAsciiRepresentation()) { |
VectorIterator<uc16> buf1(vec1); |
- VectorIterator<char> ib(other->ToAsciiVector()); |
+ VectorIterator<char> ib(rhs->ToAsciiVector()); |
return CompareStringContents(&buf1, &ib); |
} else { |
- Vector<const uc16> vec2(other->ToUC16Vector()); |
+ Vector<const uc16> vec2(rhs->ToUC16Vector()); |
return CompareRawStringContents(vec1, vec2); |
} |
} else { |
VectorIterator<uc16> buf1(vec1); |
- string_compare_buffer_b.Reset(0, other); |
+ string_compare_buffer_b.Reset(0, rhs); |
return CompareStringContents(&buf1, &string_compare_buffer_b); |
} |
} |
} else { |
- string_compare_buffer_a.Reset(0, this); |
- return CompareStringContentsPartial(&string_compare_buffer_a, other); |
+ string_compare_buffer_a.Reset(0, lhs); |
+ return CompareStringContentsPartial(&string_compare_buffer_a, rhs); |
} |
} |
@@ -7038,15 +7045,9 @@ class SymbolKey : public HashTableKey { |
} |
Object* AsObject() { |
- // If the string is a cons string, attempt to flatten it so that |
- // symbols will most often be flat strings. |
- if (StringShape(string_).IsCons()) { |
- ConsString* cons_string = ConsString::cast(string_); |
- cons_string->TryFlatten(); |
- if (cons_string->second()->length() == 0) { |
- string_ = cons_string->first(); |
- } |
- } |
+ // Attempt to flatten the string, so that symbols will most often |
+ // be flat strings. |
+ string_ = string_->TryFlattenGetString(); |
// Transform string to symbol if possible. |
Map* map = Heap::SymbolMapForString(string_); |
if (map != NULL) { |