Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 10063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10074 TwoByteString::CharAddr(strobj, 0), len); | 10074 TwoByteString::CharAddr(strobj, 0), len); |
| 10075 return strobj.raw(); | 10075 return strobj.raw(); |
| 10076 } | 10076 } |
| 10077 | 10077 |
| 10078 | 10078 |
| 10079 RawString* String::New(const uint16_t* utf16_array, | 10079 RawString* String::New(const uint16_t* utf16_array, |
| 10080 intptr_t array_len, | 10080 intptr_t array_len, |
| 10081 Heap::Space space) { | 10081 Heap::Space space) { |
| 10082 bool is_one_byte_string = true; | 10082 bool is_one_byte_string = true; |
| 10083 for (intptr_t i = 0; i < array_len; ++i) { | 10083 for (intptr_t i = 0; i < array_len; ++i) { |
| 10084 if (utf16_array[i] > 0xFF) { | 10084 if (!Utf::IsLatin1(utf16_array[i])) { |
| 10085 is_one_byte_string = false; | 10085 is_one_byte_string = false; |
| 10086 break; | 10086 break; |
| 10087 } | 10087 } |
| 10088 } | 10088 } |
| 10089 if (is_one_byte_string) { | 10089 if (is_one_byte_string) { |
| 10090 return OneByteString::New(utf16_array, array_len, space); | 10090 return OneByteString::New(utf16_array, array_len, space); |
| 10091 } | 10091 } |
| 10092 return TwoByteString::New(utf16_array, array_len, space); | 10092 return TwoByteString::New(utf16_array, array_len, space); |
| 10093 } | 10093 } |
| 10094 | 10094 |
| 10095 | 10095 |
| 10096 RawString* String::New(const int32_t* utf32_array, | 10096 RawString* String::New(const int32_t* utf32_array, |
| 10097 intptr_t array_len, | 10097 intptr_t array_len, |
| 10098 Heap::Space space) { | 10098 Heap::Space space) { |
| 10099 bool is_one_byte_string = true; | 10099 bool is_one_byte_string = true; |
| 10100 intptr_t utf16_len = array_len; | 10100 intptr_t utf16_len = array_len; |
| 10101 for (intptr_t i = 0; i < array_len; ++i) { | 10101 for (intptr_t i = 0; i < array_len; ++i) { |
| 10102 if (utf32_array[i] > 0xFF) { | 10102 if (!Utf::IsLatin1(utf32_array[i])) { |
| 10103 is_one_byte_string = false; | 10103 is_one_byte_string = false; |
| 10104 } | 10104 } |
| 10105 if (utf32_array[i] > 0xFFFF) { | 10105 if (Utf::IsSupplementary(utf32_array[i])) { |
|
cshapiro
2012/11/30 03:21:24
I pulled this check into the preceding if statemen
| |
| 10106 utf16_len += 1; | 10106 utf16_len += 1; |
| 10107 } | 10107 } |
| 10108 } | 10108 } |
| 10109 if (is_one_byte_string) { | 10109 if (is_one_byte_string) { |
| 10110 return OneByteString::New(utf32_array, array_len, space); | 10110 return OneByteString::New(utf32_array, array_len, space); |
| 10111 } | 10111 } |
| 10112 return TwoByteString::New(utf16_len, utf32_array, array_len, space); | 10112 return TwoByteString::New(utf16_len, utf32_array, array_len, space); |
| 10113 } | 10113 } |
| 10114 | 10114 |
| 10115 | 10115 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10173 | 10173 |
| 10174 void String::Copy(const String& dst, intptr_t dst_offset, | 10174 void String::Copy(const String& dst, intptr_t dst_offset, |
| 10175 const uint16_t* utf16_array, | 10175 const uint16_t* utf16_array, |
| 10176 intptr_t array_len) { | 10176 intptr_t array_len) { |
| 10177 ASSERT(dst_offset >= 0); | 10177 ASSERT(dst_offset >= 0); |
| 10178 ASSERT(array_len >= 0); | 10178 ASSERT(array_len >= 0); |
| 10179 ASSERT(array_len <= (dst.Length() - dst_offset)); | 10179 ASSERT(array_len <= (dst.Length() - dst_offset)); |
| 10180 if (dst.IsOneByteString()) { | 10180 if (dst.IsOneByteString()) { |
| 10181 NoGCScope no_gc; | 10181 NoGCScope no_gc; |
| 10182 for (intptr_t i = 0; i < array_len; ++i) { | 10182 for (intptr_t i = 0; i < array_len; ++i) { |
| 10183 ASSERT(utf16_array[i] <= 0xFF); | 10183 ASSERT(Utf::IsLatin1(utf16_array[i])); |
| 10184 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i]; | 10184 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i]; |
| 10185 } | 10185 } |
| 10186 } else { | 10186 } else { |
| 10187 ASSERT(dst.IsTwoByteString()); | 10187 ASSERT(dst.IsTwoByteString()); |
| 10188 NoGCScope no_gc; | 10188 NoGCScope no_gc; |
| 10189 if (array_len > 0) { | 10189 if (array_len > 0) { |
| 10190 memmove(TwoByteString::CharAddr(dst, dst_offset), | 10190 memmove(TwoByteString::CharAddr(dst, dst_offset), |
| 10191 utf16_array, | 10191 utf16_array, |
| 10192 array_len * 2); | 10192 array_len * 2); |
| 10193 } | 10193 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10328 return Symbols::Empty(); | 10328 return Symbols::Empty(); |
| 10329 } | 10329 } |
| 10330 if (begin_index > str.Length()) { | 10330 if (begin_index > str.Length()) { |
| 10331 return String::null(); | 10331 return String::null(); |
| 10332 } | 10332 } |
| 10333 String& result = String::Handle(); | 10333 String& result = String::Handle(); |
| 10334 bool is_one_byte_string = true; | 10334 bool is_one_byte_string = true; |
| 10335 intptr_t char_size = str.CharSize(); | 10335 intptr_t char_size = str.CharSize(); |
| 10336 if (char_size == kTwoByteChar) { | 10336 if (char_size == kTwoByteChar) { |
| 10337 for (intptr_t i = begin_index; i < begin_index + length; ++i) { | 10337 for (intptr_t i = begin_index; i < begin_index + length; ++i) { |
| 10338 if (str.CharAt(i) > 0xFF) { | 10338 if (!Utf::IsLatin1(str.CharAt(i))) { |
| 10339 is_one_byte_string = false; | 10339 is_one_byte_string = false; |
| 10340 break; | 10340 break; |
| 10341 } | 10341 } |
| 10342 } | 10342 } |
| 10343 } | 10343 } |
| 10344 if (is_one_byte_string) { | 10344 if (is_one_byte_string) { |
| 10345 result ^= OneByteString::New(length, space); | 10345 result ^= OneByteString::New(length, space); |
| 10346 } else { | 10346 } else { |
| 10347 result ^= TwoByteString::New(length, space); | 10347 result ^= TwoByteString::New(length, space); |
| 10348 } | 10348 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10464 int32_t src = it.Current(); | 10464 int32_t src = it.Current(); |
| 10465 int32_t dst = mapping(src); | 10465 int32_t dst = mapping(src); |
| 10466 if (src != dst) { | 10466 if (src != dst) { |
| 10467 has_mapping = true; | 10467 has_mapping = true; |
| 10468 } | 10468 } |
| 10469 dst_max = Utils::Maximum(dst_max, dst); | 10469 dst_max = Utils::Maximum(dst_max, dst); |
| 10470 } | 10470 } |
| 10471 if (!has_mapping) { | 10471 if (!has_mapping) { |
| 10472 return str.raw(); | 10472 return str.raw(); |
| 10473 } | 10473 } |
| 10474 if (dst_max <= 0xFF) { | 10474 if (Utf::IsLatin1(dst_max)) { |
| 10475 return OneByteString::Transform(mapping, str, space); | 10475 return OneByteString::Transform(mapping, str, space); |
| 10476 } | 10476 } |
| 10477 ASSERT(dst_max > 0xFF); | 10477 ASSERT(Utf::IsBmp(dst_max) || Utf::IsSupplementary(dst_max)); |
| 10478 return TwoByteString::Transform(mapping, str, space); | 10478 return TwoByteString::Transform(mapping, str, space); |
| 10479 } | 10479 } |
| 10480 | 10480 |
| 10481 | 10481 |
| 10482 RawString* String::ToUpperCase(const String& str, Heap::Space space) { | 10482 RawString* String::ToUpperCase(const String& str, Heap::Space space) { |
| 10483 // TODO(cshapiro): create a fast-path for OneByteString instances. | 10483 // TODO(cshapiro): create a fast-path for OneByteString instances. |
| 10484 return Transform(CaseMapping::ToUpper, str, space); | 10484 return Transform(CaseMapping::ToUpper, str, space); |
| 10485 } | 10485 } |
| 10486 | 10486 |
| 10487 | 10487 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10634 } | 10634 } |
| 10635 return OneByteString::raw(result); | 10635 return OneByteString::raw(result); |
| 10636 } | 10636 } |
| 10637 | 10637 |
| 10638 | 10638 |
| 10639 RawOneByteString* OneByteString::New(const uint16_t* characters, | 10639 RawOneByteString* OneByteString::New(const uint16_t* characters, |
| 10640 intptr_t len, | 10640 intptr_t len, |
| 10641 Heap::Space space) { | 10641 Heap::Space space) { |
| 10642 const String& result =String::Handle(OneByteString::New(len, space)); | 10642 const String& result =String::Handle(OneByteString::New(len, space)); |
| 10643 for (intptr_t i = 0; i < len; ++i) { | 10643 for (intptr_t i = 0; i < len; ++i) { |
| 10644 ASSERT(characters[i] <= 0xFF); | 10644 ASSERT(Utf::IsLatin1(characters[i])); |
| 10645 *CharAddr(result, i) = characters[i]; | 10645 *CharAddr(result, i) = characters[i]; |
| 10646 } | 10646 } |
| 10647 return OneByteString::raw(result); | 10647 return OneByteString::raw(result); |
| 10648 } | 10648 } |
| 10649 | 10649 |
| 10650 | 10650 |
| 10651 RawOneByteString* OneByteString::New(const int32_t* characters, | 10651 RawOneByteString* OneByteString::New(const int32_t* characters, |
| 10652 intptr_t len, | 10652 intptr_t len, |
| 10653 Heap::Space space) { | 10653 Heap::Space space) { |
| 10654 const String& result = String::Handle(OneByteString::New(len, space)); | 10654 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10655 for (intptr_t i = 0; i < len; ++i) { | 10655 for (intptr_t i = 0; i < len; ++i) { |
| 10656 ASSERT(characters[i] <= 0xFF); | 10656 ASSERT(Utf::IsLatin1(characters[i])); |
| 10657 *CharAddr(result, i) = characters[i]; | 10657 *CharAddr(result, i) = characters[i]; |
| 10658 } | 10658 } |
| 10659 return OneByteString::raw(result); | 10659 return OneByteString::raw(result); |
| 10660 } | 10660 } |
| 10661 | 10661 |
| 10662 | 10662 |
| 10663 RawOneByteString* OneByteString::New(const String& str, | 10663 RawOneByteString* OneByteString::New(const String& str, |
| 10664 Heap::Space space) { | 10664 Heap::Space space) { |
| 10665 intptr_t len = str.Length(); | 10665 intptr_t len = str.Length(); |
| 10666 const String& result = String::Handle(OneByteString::New(len, space)); | 10666 const String& result = String::Handle(OneByteString::New(len, space)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10716 | 10716 |
| 10717 | 10717 |
| 10718 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), | 10718 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), |
| 10719 const String& str, | 10719 const String& str, |
| 10720 Heap::Space space) { | 10720 Heap::Space space) { |
| 10721 ASSERT(!str.IsNull()); | 10721 ASSERT(!str.IsNull()); |
| 10722 intptr_t len = str.Length(); | 10722 intptr_t len = str.Length(); |
| 10723 const String& result = String::Handle(OneByteString::New(len, space)); | 10723 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10724 for (intptr_t i = 0; i < len; ++i) { | 10724 for (intptr_t i = 0; i < len; ++i) { |
| 10725 int32_t ch = mapping(str.CharAt(i)); | 10725 int32_t ch = mapping(str.CharAt(i)); |
| 10726 ASSERT(ch >= 0 && ch <= 0xFF); | 10726 ASSERT(Utf::IsLatin1(ch)); |
| 10727 *CharAddr(result, i) = ch; | 10727 *CharAddr(result, i) = ch; |
| 10728 } | 10728 } |
| 10729 return OneByteString::raw(result); | 10729 return OneByteString::raw(result); |
| 10730 } | 10730 } |
| 10731 | 10731 |
| 10732 | 10732 |
| 10733 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, | 10733 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, |
| 10734 bool raw_str) { | 10734 bool raw_str) { |
| 10735 intptr_t len = str.Length(); | 10735 intptr_t len = str.Length(); |
| 10736 if (len > 0) { | 10736 if (len > 0) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10801 RawTwoByteString* TwoByteString::New(intptr_t utf16_len, | 10801 RawTwoByteString* TwoByteString::New(intptr_t utf16_len, |
| 10802 const int32_t* utf32_array, | 10802 const int32_t* utf32_array, |
| 10803 intptr_t array_len, | 10803 intptr_t array_len, |
| 10804 Heap::Space space) { | 10804 Heap::Space space) { |
| 10805 ASSERT((array_len > 0) && (utf16_len >= array_len)); | 10805 ASSERT((array_len > 0) && (utf16_len >= array_len)); |
| 10806 const String& result = String::Handle(TwoByteString::New(utf16_len, space)); | 10806 const String& result = String::Handle(TwoByteString::New(utf16_len, space)); |
| 10807 { | 10807 { |
| 10808 NoGCScope no_gc; | 10808 NoGCScope no_gc; |
| 10809 intptr_t j = 0; | 10809 intptr_t j = 0; |
| 10810 for (intptr_t i = 0; i < array_len; ++i) { | 10810 for (intptr_t i = 0; i < array_len; ++i) { |
| 10811 if (utf32_array[i] > 0xffff) { | 10811 if (Utf::IsSupplementary(utf32_array[i])) { |
| 10812 ASSERT(j < (utf16_len - 1)); | 10812 ASSERT(j < (utf16_len - 1)); |
| 10813 Utf16::Encode(utf32_array[i], CharAddr(result, j)); | 10813 Utf16::Encode(utf32_array[i], CharAddr(result, j)); |
| 10814 j += 2; | 10814 j += 2; |
| 10815 } else { | 10815 } else { |
| 10816 ASSERT(j < utf16_len); | 10816 ASSERT(j < utf16_len); |
| 10817 *CharAddr(result, j) = utf32_array[i]; | 10817 *CharAddr(result, j) = utf32_array[i]; |
| 10818 j += 1; | 10818 j += 1; |
| 10819 } | 10819 } |
| 10820 } | 10820 } |
| 10821 } | 10821 } |
| (...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12077 } | 12077 } |
| 12078 return result.raw(); | 12078 return result.raw(); |
| 12079 } | 12079 } |
| 12080 | 12080 |
| 12081 | 12081 |
| 12082 const char* WeakProperty::ToCString() const { | 12082 const char* WeakProperty::ToCString() const { |
| 12083 return "_WeakProperty"; | 12083 return "_WeakProperty"; |
| 12084 } | 12084 } |
| 12085 | 12085 |
| 12086 } // namespace dart | 12086 } // namespace dart |
| OLD | NEW |