Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index ca04df567c082a3df3ca1581cecfeb6a687f5a59..266ce0fecccf1aac1bcebb1fcd0d605e6076c6d2 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -5072,6 +5072,12 @@ int32_t String::CharAt(intptr_t index) const { |
| } |
| +void String::SetCharAt(intptr_t index, int32_t value) const { |
| + // String is an abstract class. |
| + UNREACHABLE(); |
| +} |
| + |
| + |
| bool String::Equals(const Instance& other) const { |
| if (this->raw() == other.raw()) { |
| // Both handles point to the same raw instance. |
| @@ -5721,6 +5727,61 @@ const char* String::ToCString() const { |
| } |
| +template<typename T> |
| +static RawString* CaseMappingImpl(T mapping, |
| + const String& str, |
| + Heap::Space space) { |
| + ASSERT(!str.IsNull()); |
|
Ivan Posva
2011/10/18 22:01:13
Please add a TODO in this function that outlines s
cshapiro
2011/10/20 02:35:05
Done. I have added a TODO here about speculation.
|
| + bool has_mapping = false; |
| + int32_t dst_max = -1; |
| + intptr_t len = str.Length(); |
| + for (intptr_t i = 0; i < len; ++i) { |
| + int32_t src = str.CharAt(i); |
| + int32_t dst = mapping(src); |
| + if (src != dst) { |
| + has_mapping = true; |
| + } |
| + dst_max = Utils::Maximum(dst_max, dst); |
| + } |
| + if (!has_mapping) { |
| + return str.raw(); |
| + } |
| + if (dst_max <= 0xFF) { |
| + const OneByteString& onestr = |
| + OneByteString::Handle(OneByteString::New(len, space)); |
| + for (intptr_t i = 0; i < len; ++i) { |
| + onestr.SetCharAt(i, mapping(str.CharAt(i))); |
| + } |
| + return onestr.raw(); |
| + } |
| + if (dst_max <= 0xFFFF) { |
| + const TwoByteString& twostr = |
| + TwoByteString::Handle(TwoByteString::New(len, space)); |
| + for (intptr_t i = 0; i < len; ++i) { |
| + twostr.SetCharAt(i, mapping(str.CharAt(i))); |
| + } |
| + return twostr.raw(); |
| + } |
| + ASSERT(dst_max > 0xFFFF); |
| + const FourByteString& fourstr = |
| + FourByteString::Handle(FourByteString::New(len, space)); |
| + for (intptr_t i = 0; i < len; ++i) { |
| + fourstr.SetCharAt(i, mapping(str.CharAt(i))); |
| + } |
| + return fourstr.raw(); |
| +} |
| + |
| + |
| +RawString* String::ToUpperCase(const String& str, Heap::Space space) { |
| + return CaseMappingImpl(CaseMapping::ToUpper, str, space); |
| +} |
| + |
| + |
| +RawString* String::ToLowerCase(const String& str, Heap::Space space) { |
| + return CaseMappingImpl(CaseMapping::ToLower, str, space); |
| +} |
| + |
| + |
| RawOneByteString* OneByteString::New(intptr_t len, |
| Heap::Space space) { |
| Isolate* isolate = Isolate::Current(); |