Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index 519909c914185aa899860cb77ee185304db815d9..177febb00a0d8ebef88eb199f0b7f39bbb1a01e1 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -5181,7 +5181,7 @@ uint16_t ConsString::ConsStringGet(int index) { |
| // Check for a flattened cons string |
| if (second()->length() == 0) { |
| String* left = first(); |
| - return left->Get(index); |
| + return FlatString::cast(left)->FlatStringGet(index); |
| } |
| String* string = String::cast(this); |
| @@ -5197,7 +5197,7 @@ uint16_t ConsString::ConsStringGet(int index) { |
| string = cons_string->second(); |
| } |
| } else { |
| - return string->Get(index); |
| + return FlatString::cast(string)->FlatStringGet(index); |
| } |
| } |
| @@ -5206,6 +5206,20 @@ uint16_t ConsString::ConsStringGet(int index) { |
| } |
| +MaybeObject* ConsString::ConsStringGetMayFlatten(int index) { |
| + ASSERT(index >= 0); |
| + ASSERT(index < this->length()); |
| + |
| + String* string = this; |
| + if (this->GetIsolate()->ShouldFlattenString()) { |
|
Vitaly Repeshko
2011/05/10 13:07:02
Here "this" can already be a flat cons (i.e. with
Lasse Reichstein
2011/05/10 16:27:46
Good point. We should probably not get here for a
|
| + MaybeObject* flatten_result = this->TryFlatten(); |
| + if (flatten_result->IsFailure()) return flatten_result; |
| + string = String::cast(flatten_result->ToObjectUnchecked()); |
| + } |
| + return Smi::FromInt(string->Get(index)); |
| +} |
| + |
| + |
| template <typename sinkchar> |
| void String::WriteToFlat(String* src, |
| sinkchar* sink, |