Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 5054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5065 } | 5065 } |
| 5066 | 5066 |
| 5067 | 5067 |
| 5068 int32_t String::CharAt(intptr_t index) const { | 5068 int32_t String::CharAt(intptr_t index) const { |
| 5069 // String is an abstract class. | 5069 // String is an abstract class. |
| 5070 UNREACHABLE(); | 5070 UNREACHABLE(); |
| 5071 return 0; | 5071 return 0; |
| 5072 } | 5072 } |
| 5073 | 5073 |
| 5074 | 5074 |
| 5075 void String::SetCharAt(intptr_t index, int32_t value) const { | |
| 5076 // String is an abstract class. | |
| 5077 UNREACHABLE(); | |
| 5078 } | |
| 5079 | |
| 5080 | |
| 5075 bool String::Equals(const Instance& other) const { | 5081 bool String::Equals(const Instance& other) const { |
| 5076 if (this->raw() == other.raw()) { | 5082 if (this->raw() == other.raw()) { |
| 5077 // Both handles point to the same raw instance. | 5083 // Both handles point to the same raw instance. |
| 5078 return true; | 5084 return true; |
| 5079 } | 5085 } |
| 5080 | 5086 |
| 5081 if (!other.IsString() || other.IsNull()) { | 5087 if (!other.IsString() || other.IsNull()) { |
| 5082 return false; | 5088 return false; |
| 5083 } | 5089 } |
| 5084 | 5090 |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5714 const char* String::ToCString() const { | 5720 const char* String::ToCString() const { |
| 5715 intptr_t len = Utf8::Length(*this); | 5721 intptr_t len = Utf8::Length(*this); |
| 5716 Zone* zone = Isolate::Current()->current_zone(); | 5722 Zone* zone = Isolate::Current()->current_zone(); |
| 5717 char* result = reinterpret_cast<char*>(zone->Allocate(len + 1)); | 5723 char* result = reinterpret_cast<char*>(zone->Allocate(len + 1)); |
| 5718 Utf8::Encode(*this, result, len); | 5724 Utf8::Encode(*this, result, len); |
| 5719 result[len] = 0; | 5725 result[len] = 0; |
| 5720 return result; | 5726 return result; |
| 5721 } | 5727 } |
| 5722 | 5728 |
| 5723 | 5729 |
| 5730 template<typename T> | |
| 5731 static RawString* CaseMappingImpl(T mapping, | |
| 5732 const String& str, | |
| 5733 Heap::Space space) { | |
| 5734 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.
| |
| 5735 bool has_mapping = false; | |
| 5736 int32_t dst_max = -1; | |
| 5737 intptr_t len = str.Length(); | |
| 5738 for (intptr_t i = 0; i < len; ++i) { | |
| 5739 int32_t src = str.CharAt(i); | |
| 5740 int32_t dst = mapping(src); | |
| 5741 if (src != dst) { | |
| 5742 has_mapping = true; | |
| 5743 } | |
| 5744 dst_max = Utils::Maximum(dst_max, dst); | |
| 5745 } | |
| 5746 if (!has_mapping) { | |
| 5747 return str.raw(); | |
| 5748 } | |
| 5749 if (dst_max <= 0xFF) { | |
| 5750 const OneByteString& onestr = | |
| 5751 OneByteString::Handle(OneByteString::New(len, space)); | |
| 5752 for (intptr_t i = 0; i < len; ++i) { | |
| 5753 onestr.SetCharAt(i, mapping(str.CharAt(i))); | |
| 5754 } | |
| 5755 return onestr.raw(); | |
| 5756 } | |
| 5757 if (dst_max <= 0xFFFF) { | |
| 5758 const TwoByteString& twostr = | |
| 5759 TwoByteString::Handle(TwoByteString::New(len, space)); | |
| 5760 for (intptr_t i = 0; i < len; ++i) { | |
| 5761 twostr.SetCharAt(i, mapping(str.CharAt(i))); | |
| 5762 } | |
| 5763 return twostr.raw(); | |
| 5764 } | |
| 5765 ASSERT(dst_max > 0xFFFF); | |
| 5766 const FourByteString& fourstr = | |
| 5767 FourByteString::Handle(FourByteString::New(len, space)); | |
| 5768 for (intptr_t i = 0; i < len; ++i) { | |
| 5769 fourstr.SetCharAt(i, mapping(str.CharAt(i))); | |
| 5770 } | |
| 5771 return fourstr.raw(); | |
| 5772 } | |
| 5773 | |
| 5774 | |
| 5775 RawString* String::ToUpperCase(const String& str, Heap::Space space) { | |
| 5776 return CaseMappingImpl(CaseMapping::ToUpper, str, space); | |
| 5777 } | |
| 5778 | |
| 5779 | |
| 5780 RawString* String::ToLowerCase(const String& str, Heap::Space space) { | |
| 5781 return CaseMappingImpl(CaseMapping::ToLower, str, space); | |
| 5782 } | |
| 5783 | |
| 5784 | |
| 5724 RawOneByteString* OneByteString::New(intptr_t len, | 5785 RawOneByteString* OneByteString::New(intptr_t len, |
| 5725 Heap::Space space) { | 5786 Heap::Space space) { |
| 5726 Isolate* isolate = Isolate::Current(); | 5787 Isolate* isolate = Isolate::Current(); |
| 5727 | 5788 |
| 5728 const Class& cls = | 5789 const Class& cls = |
| 5729 Class::Handle(isolate->object_store()->one_byte_string_class()); | 5790 Class::Handle(isolate->object_store()->one_byte_string_class()); |
| 5730 OneByteString& result = OneByteString::Handle(); | 5791 OneByteString& result = OneByteString::Handle(); |
| 5731 { | 5792 { |
| 5732 RawObject* raw = Object::Allocate(cls, | 5793 RawObject* raw = Object::Allocate(cls, |
| 5733 OneByteString::InstanceSize(len), | 5794 OneByteString::InstanceSize(len), |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6445 const String& str = String::Handle(pattern()); | 6506 const String& str = String::Handle(pattern()); |
| 6446 const char* format = "JSRegExp: pattern=%s flags=%s"; | 6507 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 6447 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 6508 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 6448 char* chars = reinterpret_cast<char*>( | 6509 char* chars = reinterpret_cast<char*>( |
| 6449 Isolate::Current()->current_zone()->Allocate(len + 1)); | 6510 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 6450 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 6511 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 6451 return chars; | 6512 return chars; |
| 6452 } | 6513 } |
| 6453 | 6514 |
| 6454 } // namespace dart | 6515 } // namespace dart |
| OLD | NEW |