| 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 cls = Class::New<UnwindError>(); | 399 cls = Class::New<UnwindError>(); |
| 400 unwind_error_class_ = cls.raw(); | 400 unwind_error_class_ = cls.raw(); |
| 401 | 401 |
| 402 ASSERT(class_class() != null_); | 402 ASSERT(class_class() != null_); |
| 403 | 403 |
| 404 // Pre-allocate the Array and OneByteString class in the vm isolate so that | 404 // Pre-allocate the Array and OneByteString class in the vm isolate so that |
| 405 // we can create a symbol table and populate it with some frequently used | 405 // we can create a symbol table and populate it with some frequently used |
| 406 // strings as symbols. | 406 // strings as symbols. |
| 407 cls = Class::New<Array>(); | 407 cls = Class::New<Array>(); |
| 408 isolate->object_store()->set_array_class(cls); | 408 isolate->object_store()->set_array_class(cls); |
| 409 cls = Class::New<OneByteString>(); | 409 cls = Class::NewStringClass(kOneByteStringCid); |
| 410 isolate->object_store()->set_one_byte_string_class(cls); | 410 isolate->object_store()->set_one_byte_string_class(cls); |
| 411 | 411 |
| 412 // Allocate and initialize the empty_array instance. | 412 // Allocate and initialize the empty_array instance. |
| 413 { | 413 { |
| 414 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); | 414 uword address = heap->Allocate(Array::InstanceSize(0), Heap::kOld); |
| 415 empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag); | 415 empty_array_ = reinterpret_cast<RawArray*>(address + kHeapObjectTag); |
| 416 InitializeObject(address, kArrayCid, Array::InstanceSize(0)); | 416 InitializeObject(address, kArrayCid, Array::InstanceSize(0)); |
| 417 empty_array_->ptr()->length_ = Smi::New(0); | 417 empty_array_->ptr()->length_ = Smi::New(0); |
| 418 } | 418 } |
| 419 } | 419 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 object_store->set_canonical_type_arguments(array); | 538 object_store->set_canonical_type_arguments(array); |
| 539 | 539 |
| 540 // Setup type class early in the process. | 540 // Setup type class early in the process. |
| 541 cls = Class::New<Type>(); | 541 cls = Class::New<Type>(); |
| 542 object_store->set_type_class(cls); | 542 object_store->set_type_class(cls); |
| 543 | 543 |
| 544 cls = Class::New<TypeParameter>(); | 544 cls = Class::New<TypeParameter>(); |
| 545 object_store->set_type_parameter_class(cls); | 545 object_store->set_type_parameter_class(cls); |
| 546 | 546 |
| 547 // Pre-allocate the OneByteString class needed by the symbol table. | 547 // Pre-allocate the OneByteString class needed by the symbol table. |
| 548 cls = Class::New<OneByteString>(); | 548 cls = Class::NewStringClass(kOneByteStringCid); |
| 549 object_store->set_one_byte_string_class(cls); | 549 object_store->set_one_byte_string_class(cls); |
| 550 | 550 |
| 551 // Setup the symbol table for the symbols created in the isolate. | 551 // Setup the symbol table for the symbols created in the isolate. |
| 552 Symbols::SetupSymbolTable(isolate); | 552 Symbols::SetupSymbolTable(isolate); |
| 553 | 553 |
| 554 // Set up the libraries array before initializing the core library. | 554 // Set up the libraries array before initializing the core library. |
| 555 const GrowableObjectArray& libraries = | 555 const GrowableObjectArray& libraries = |
| 556 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); | 556 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); |
| 557 object_store->set_libraries(libraries); | 557 object_store->set_libraries(libraries); |
| 558 | 558 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 ASSERT(object_store->immutable_array_class() != object_store->array_class()); | 599 ASSERT(object_store->immutable_array_class() != object_store->array_class()); |
| 600 name = Symbols::ImmutableArray(); | 600 name = Symbols::ImmutableArray(); |
| 601 RegisterPrivateClass(cls, name, core_lib); | 601 RegisterPrivateClass(cls, name, core_lib); |
| 602 pending_classes.Add(cls, Heap::kOld); | 602 pending_classes.Add(cls, Heap::kOld); |
| 603 | 603 |
| 604 cls = object_store->one_byte_string_class(); // Was allocated above. | 604 cls = object_store->one_byte_string_class(); // Was allocated above. |
| 605 name = Symbols::OneByteString(); | 605 name = Symbols::OneByteString(); |
| 606 RegisterPrivateClass(cls, name, core_lib); | 606 RegisterPrivateClass(cls, name, core_lib); |
| 607 pending_classes.Add(cls, Heap::kOld); | 607 pending_classes.Add(cls, Heap::kOld); |
| 608 | 608 |
| 609 cls = Class::New<TwoByteString>(); | 609 cls = Class::NewStringClass(kTwoByteStringCid); |
| 610 object_store->set_two_byte_string_class(cls); | 610 object_store->set_two_byte_string_class(cls); |
| 611 name = Symbols::TwoByteString(); | 611 name = Symbols::TwoByteString(); |
| 612 RegisterPrivateClass(cls, name, core_lib); | 612 RegisterPrivateClass(cls, name, core_lib); |
| 613 pending_classes.Add(cls, Heap::kOld); | 613 pending_classes.Add(cls, Heap::kOld); |
| 614 | 614 |
| 615 cls = Class::New<ExternalOneByteString>(); | 615 cls = Class::NewStringClass(kExternalOneByteStringCid); |
| 616 object_store->set_external_one_byte_string_class(cls); | 616 object_store->set_external_one_byte_string_class(cls); |
| 617 name = Symbols::ExternalOneByteString(); | 617 name = Symbols::ExternalOneByteString(); |
| 618 RegisterPrivateClass(cls, name, core_lib); | 618 RegisterPrivateClass(cls, name, core_lib); |
| 619 pending_classes.Add(cls, Heap::kOld); | 619 pending_classes.Add(cls, Heap::kOld); |
| 620 | 620 |
| 621 cls = Class::New<ExternalTwoByteString>(); | 621 cls = Class::NewStringClass(kExternalTwoByteStringCid); |
| 622 object_store->set_external_two_byte_string_class(cls); | 622 object_store->set_external_two_byte_string_class(cls); |
| 623 name = Symbols::ExternalTwoByteString(); | 623 name = Symbols::ExternalTwoByteString(); |
| 624 RegisterPrivateClass(cls, name, core_lib); | 624 RegisterPrivateClass(cls, name, core_lib); |
| 625 pending_classes.Add(cls, Heap::kOld); | 625 pending_classes.Add(cls, Heap::kOld); |
| 626 | 626 |
| 627 cls = Class::New<Stacktrace>(); | 627 cls = Class::New<Stacktrace>(); |
| 628 object_store->set_stacktrace_class(cls); | 628 object_store->set_stacktrace_class(cls); |
| 629 name = Symbols::Stacktrace(); | 629 name = Symbols::Stacktrace(); |
| 630 RegisterClass(cls, name, core_impl_lib); | 630 RegisterClass(cls, name, core_impl_lib); |
| 631 pending_classes.Add(cls, Heap::kOld); | 631 pending_classes.Add(cls, Heap::kOld); |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 | 1078 |
| 1079 cls = Class::New<Mint>(); | 1079 cls = Class::New<Mint>(); |
| 1080 object_store->set_mint_class(cls); | 1080 object_store->set_mint_class(cls); |
| 1081 | 1081 |
| 1082 cls = Class::New<Double>(); | 1082 cls = Class::New<Double>(); |
| 1083 object_store->set_double_class(cls); | 1083 object_store->set_double_class(cls); |
| 1084 | 1084 |
| 1085 cls = Class::New<Bigint>(); | 1085 cls = Class::New<Bigint>(); |
| 1086 object_store->set_bigint_class(cls); | 1086 object_store->set_bigint_class(cls); |
| 1087 | 1087 |
| 1088 cls = Class::New<OneByteString>(); | 1088 cls = Class::NewStringClass(kOneByteStringCid); |
| 1089 object_store->set_one_byte_string_class(cls); | 1089 object_store->set_one_byte_string_class(cls); |
| 1090 | 1090 |
| 1091 cls = Class::New<TwoByteString>(); | 1091 cls = Class::NewStringClass(kTwoByteStringCid); |
| 1092 object_store->set_two_byte_string_class(cls); | 1092 object_store->set_two_byte_string_class(cls); |
| 1093 | 1093 |
| 1094 cls = Class::New<ExternalOneByteString>(); | 1094 cls = Class::NewStringClass(kExternalOneByteStringCid); |
| 1095 object_store->set_external_one_byte_string_class(cls); | 1095 object_store->set_external_one_byte_string_class(cls); |
| 1096 | 1096 |
| 1097 cls = Class::New<ExternalTwoByteString>(); | 1097 cls = Class::NewStringClass(kExternalTwoByteStringCid); |
| 1098 object_store->set_external_two_byte_string_class(cls); | 1098 object_store->set_external_two_byte_string_class(cls); |
| 1099 | 1099 |
| 1100 cls = Class::New<Bool>(); | 1100 cls = Class::New<Bool>(); |
| 1101 object_store->set_bool_class(cls); | 1101 object_store->set_bool_class(cls); |
| 1102 | 1102 |
| 1103 cls = Class::New<Stacktrace>(); | 1103 cls = Class::New<Stacktrace>(); |
| 1104 object_store->set_stacktrace_class(cls); | 1104 object_store->set_stacktrace_class(cls); |
| 1105 | 1105 |
| 1106 cls = Class::New<JSRegExp>(); | 1106 cls = Class::New<JSRegExp>(); |
| 1107 object_store->set_jsregexp_class(cls); | 1107 object_store->set_jsregexp_class(cls); |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1871 cls.set_num_native_fields(field_count); | 1871 cls.set_num_native_fields(field_count); |
| 1872 cls.set_is_finalized(); | 1872 cls.set_is_finalized(); |
| 1873 library.AddClass(cls); | 1873 library.AddClass(cls); |
| 1874 return cls.raw(); | 1874 return cls.raw(); |
| 1875 } else { | 1875 } else { |
| 1876 return Class::null(); | 1876 return Class::null(); |
| 1877 } | 1877 } |
| 1878 } | 1878 } |
| 1879 | 1879 |
| 1880 | 1880 |
| 1881 RawClass* Class::NewStringClass(intptr_t class_id) { |
| 1882 intptr_t instance_size; |
| 1883 if (class_id == kOneByteStringCid) { |
| 1884 instance_size = OneByteString::InstanceSize(); |
| 1885 } else if (class_id == kTwoByteStringCid) { |
| 1886 instance_size = TwoByteString::InstanceSize(); |
| 1887 } else if (class_id == kExternalOneByteStringCid) { |
| 1888 instance_size = ExternalOneByteString::InstanceSize(); |
| 1889 } else { |
| 1890 ASSERT(class_id == kExternalTwoByteStringCid); |
| 1891 instance_size = ExternalTwoByteString::InstanceSize(); |
| 1892 } |
| 1893 Class& result = Class::Handle(New<String>(class_id)); |
| 1894 result.set_instance_size(instance_size); |
| 1895 result.set_next_field_offset(instance_size); |
| 1896 result.set_is_prefinalized(); |
| 1897 return result.raw(); |
| 1898 } |
| 1899 |
| 1900 |
| 1881 void Class::set_name(const String& value) const { | 1901 void Class::set_name(const String& value) const { |
| 1882 ASSERT(value.IsSymbol()); | 1902 ASSERT(value.IsSymbol()); |
| 1883 StorePointer(&raw_ptr()->name_, value.raw()); | 1903 StorePointer(&raw_ptr()->name_, value.raw()); |
| 1884 } | 1904 } |
| 1885 | 1905 |
| 1886 | 1906 |
| 1887 void Class::set_script(const Script& value) const { | 1907 void Class::set_script(const Script& value) const { |
| 1888 StorePointer(&raw_ptr()->script_, value.raw()); | 1908 StorePointer(&raw_ptr()->script_, value.raw()); |
| 1889 } | 1909 } |
| 1890 | 1910 |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2184 return false; | 2204 return false; |
| 2185 } | 2205 } |
| 2186 } | 2206 } |
| 2187 return true; | 2207 return true; |
| 2188 } | 2208 } |
| 2189 | 2209 |
| 2190 | 2210 |
| 2191 RawFunction* Class::LookupFunction(const String& name) const { | 2211 RawFunction* Class::LookupFunction(const String& name) const { |
| 2192 Isolate* isolate = Isolate::Current(); | 2212 Isolate* isolate = Isolate::Current(); |
| 2193 ASSERT(name.IsOneByteString()); | 2213 ASSERT(name.IsOneByteString()); |
| 2194 const OneByteString& lookup_name = OneByteString::Cast(name); | |
| 2195 Array& funcs = Array::Handle(isolate, functions()); | 2214 Array& funcs = Array::Handle(isolate, functions()); |
| 2196 if (funcs.IsNull()) { | 2215 if (funcs.IsNull()) { |
| 2197 // This can occur, e.g., for Null classes. | 2216 // This can occur, e.g., for Null classes. |
| 2198 return Function::null(); | 2217 return Function::null(); |
| 2199 } | 2218 } |
| 2200 Function& function = Function::Handle(isolate, Function::null()); | 2219 Function& function = Function::Handle(isolate, Function::null()); |
| 2201 OneByteString& function_name = | 2220 String& function_name = String::Handle(isolate, String::null()); |
| 2202 OneByteString::Handle(isolate, OneByteString::null()); | |
| 2203 intptr_t len = funcs.Length(); | 2221 intptr_t len = funcs.Length(); |
| 2204 for (intptr_t i = 0; i < len; i++) { | 2222 for (intptr_t i = 0; i < len; i++) { |
| 2205 function ^= funcs.At(i); | 2223 function ^= funcs.At(i); |
| 2206 function_name ^= function.name(); | 2224 function_name ^= function.name(); |
| 2207 if (function_name.EqualsIgnoringPrivateKey(lookup_name)) { | 2225 if (OneByteString::EqualsIgnoringPrivateKey(function_name, name)) { |
| 2208 return function.raw(); | 2226 return function.raw(); |
| 2209 } | 2227 } |
| 2210 } | 2228 } |
| 2211 | 2229 |
| 2212 // No function found. | 2230 // No function found. |
| 2213 return Function::null(); | 2231 return Function::null(); |
| 2214 } | 2232 } |
| 2215 | 2233 |
| 2216 | 2234 |
| 2217 RawFunction* Class::LookupGetterFunction(const String& name) const { | 2235 RawFunction* Class::LookupGetterFunction(const String& name) const { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2293 return field.raw(); | 2311 return field.raw(); |
| 2294 } | 2312 } |
| 2295 // No field found. | 2313 // No field found. |
| 2296 return Field::null(); | 2314 return Field::null(); |
| 2297 } | 2315 } |
| 2298 | 2316 |
| 2299 | 2317 |
| 2300 RawField* Class::LookupField(const String& name) const { | 2318 RawField* Class::LookupField(const String& name) const { |
| 2301 Isolate* isolate = Isolate::Current(); | 2319 Isolate* isolate = Isolate::Current(); |
| 2302 ASSERT(name.IsOneByteString()); | 2320 ASSERT(name.IsOneByteString()); |
| 2303 const OneByteString& lookup_name = OneByteString::Cast(name); | |
| 2304 const Array& flds = Array::Handle(isolate, fields()); | 2321 const Array& flds = Array::Handle(isolate, fields()); |
| 2305 Field& field = Field::Handle(isolate, Field::null()); | 2322 Field& field = Field::Handle(isolate, Field::null()); |
| 2306 OneByteString& field_name = | 2323 String& field_name = String::Handle(isolate, String::null()); |
| 2307 OneByteString::Handle(isolate, OneByteString::null()); | |
| 2308 intptr_t len = flds.Length(); | 2324 intptr_t len = flds.Length(); |
| 2309 for (intptr_t i = 0; i < len; i++) { | 2325 for (intptr_t i = 0; i < len; i++) { |
| 2310 field ^= flds.At(i); | 2326 field ^= flds.At(i); |
| 2311 field_name ^= field.name(); | 2327 field_name ^= field.name(); |
| 2312 if (field_name.EqualsIgnoringPrivateKey(lookup_name)) { | 2328 if (OneByteString::EqualsIgnoringPrivateKey(field_name, name)) { |
| 2313 return field.raw(); | 2329 return field.raw(); |
| 2314 } | 2330 } |
| 2315 } | 2331 } |
| 2316 // No field found. | 2332 // No field found. |
| 2317 return Field::null(); | 2333 return Field::null(); |
| 2318 } | 2334 } |
| 2319 | 2335 |
| 2320 | 2336 |
| 2321 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { | 2337 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { |
| 2322 Isolate* isolate = Isolate::Current(); | 2338 Isolate* isolate = Isolate::Current(); |
| (...skipping 6682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9005 // Integer is an interface. No instances of Integer should exist. | 9021 // Integer is an interface. No instances of Integer should exist. |
| 9006 UNREACHABLE(); | 9022 UNREACHABLE(); |
| 9007 return "Integer"; | 9023 return "Integer"; |
| 9008 } | 9024 } |
| 9009 | 9025 |
| 9010 | 9026 |
| 9011 RawInteger* Integer::New(const String& str, Heap::Space space) { | 9027 RawInteger* Integer::New(const String& str, Heap::Space space) { |
| 9012 // We are not supposed to have integers represented as two byte or | 9028 // We are not supposed to have integers represented as two byte or |
| 9013 // four byte strings. | 9029 // four byte strings. |
| 9014 ASSERT(str.IsOneByteString()); | 9030 ASSERT(str.IsOneByteString()); |
| 9015 const OneByteString& onestr = OneByteString::Cast(str); | |
| 9016 int64_t value; | 9031 int64_t value; |
| 9017 if (!OS::StringToInt64(onestr.ToCString(), &value)) { | 9032 if (!OS::StringToInt64(str.ToCString(), &value)) { |
| 9018 const Bigint& big = Bigint::Handle(Bigint::New(onestr, space)); | 9033 const Bigint& big = Bigint::Handle(Bigint::New(str, space)); |
| 9019 ASSERT(!BigintOperations::FitsIntoSmi(big)); | 9034 ASSERT(!BigintOperations::FitsIntoSmi(big)); |
| 9020 ASSERT(!BigintOperations::FitsIntoMint(big)); | 9035 ASSERT(!BigintOperations::FitsIntoMint(big)); |
| 9021 return big.raw(); | 9036 return big.raw(); |
| 9022 } | 9037 } |
| 9023 return Integer::New(value, space); | 9038 return Integer::New(value, space); |
| 9024 } | 9039 } |
| 9025 | 9040 |
| 9026 | 9041 |
| 9027 RawInteger* Integer::New(int64_t value, Heap::Space space) { | 9042 RawInteger* Integer::New(int64_t value, Heap::Space space) { |
| 9028 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { | 9043 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9773 return HashImpl(characters, len); | 9788 return HashImpl(characters, len); |
| 9774 } | 9789 } |
| 9775 | 9790 |
| 9776 | 9791 |
| 9777 intptr_t String::Hash(const uint32_t* characters, intptr_t len) { | 9792 intptr_t String::Hash(const uint32_t* characters, intptr_t len) { |
| 9778 return HashImpl(characters, len); | 9793 return HashImpl(characters, len); |
| 9779 } | 9794 } |
| 9780 | 9795 |
| 9781 | 9796 |
| 9782 int32_t String::CharAt(intptr_t index) const { | 9797 int32_t String::CharAt(intptr_t index) const { |
| 9783 // String is an abstract class. | 9798 intptr_t class_id = raw()->GetClassId(); |
| 9784 UNREACHABLE(); | 9799 ASSERT(RawObject::IsStringClassId(class_id)); |
| 9785 return 0; | 9800 NoGCScope no_gc; |
| 9801 if (class_id == kOneByteStringCid) { |
| 9802 return *OneByteString::CharAddr(*this, index); |
| 9803 } |
| 9804 if (class_id == kTwoByteStringCid) { |
| 9805 return *TwoByteString::CharAddr(*this, index); |
| 9806 } |
| 9807 if (class_id == kExternalOneByteStringCid) { |
| 9808 return *ExternalOneByteString::CharAddr(*this, index); |
| 9809 } |
| 9810 ASSERT(class_id == kExternalTwoByteStringCid); |
| 9811 return *ExternalTwoByteString::CharAddr(*this, index); |
| 9786 } | 9812 } |
| 9787 | 9813 |
| 9788 | 9814 |
| 9789 intptr_t String::CharSize() const { | 9815 intptr_t String::CharSize() const { |
| 9790 // String is an abstract class. | 9816 intptr_t class_id = raw()->GetClassId(); |
| 9791 UNREACHABLE(); | 9817 if (class_id == kOneByteStringCid || class_id == kExternalOneByteStringCid) { |
| 9792 return 0; | 9818 return kOneByteChar; |
| 9819 } |
| 9820 ASSERT(class_id == kTwoByteStringCid || |
| 9821 class_id == kExternalTwoByteStringCid); |
| 9822 return kTwoByteChar; |
| 9793 } | 9823 } |
| 9794 | 9824 |
| 9795 | 9825 |
| 9826 void* String::GetPeer() const { |
| 9827 intptr_t class_id = raw()->GetClassId(); |
| 9828 if (class_id == kExternalOneByteStringCid) { |
| 9829 return ExternalOneByteString::GetPeer(*this); |
| 9830 } |
| 9831 ASSERT(class_id == kExternalTwoByteStringCid); |
| 9832 return ExternalTwoByteString::GetPeer(*this); |
| 9833 } |
| 9834 |
| 9835 |
| 9796 bool String::Equals(const Instance& other) const { | 9836 bool String::Equals(const Instance& other) const { |
| 9797 if (this->raw() == other.raw()) { | 9837 if (this->raw() == other.raw()) { |
| 9798 // Both handles point to the same raw instance. | 9838 // Both handles point to the same raw instance. |
| 9799 return true; | 9839 return true; |
| 9800 } | 9840 } |
| 9801 | 9841 |
| 9802 if (!other.IsString() || other.IsNull()) { | 9842 if (!other.IsString() || other.IsNull()) { |
| 9803 return false; | 9843 return false; |
| 9804 } | 9844 } |
| 9805 | 9845 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9928 return String::New(utf8_array, array_len, space); | 9968 return String::New(utf8_array, array_len, space); |
| 9929 } | 9969 } |
| 9930 | 9970 |
| 9931 | 9971 |
| 9932 RawString* String::New(const uint8_t* utf8_array, | 9972 RawString* String::New(const uint8_t* utf8_array, |
| 9933 intptr_t array_len, | 9973 intptr_t array_len, |
| 9934 Heap::Space space) { | 9974 Heap::Space space) { |
| 9935 Utf8::Type type; | 9975 Utf8::Type type; |
| 9936 intptr_t len = Utf8::CodePointCount(utf8_array, array_len, &type); | 9976 intptr_t len = Utf8::CodePointCount(utf8_array, array_len, &type); |
| 9937 if (type == Utf8::kAscii) { | 9977 if (type == Utf8::kAscii) { |
| 9938 const OneByteString& strobj | 9978 const String& strobj = String::Handle(OneByteString::New(len, space)); |
| 9939 = OneByteString::Handle(OneByteString::New(len, space)); | |
| 9940 if (len > 0) { | 9979 if (len > 0) { |
| 9941 NoGCScope no_gc; | 9980 NoGCScope no_gc; |
| 9942 Utf8::DecodeToAscii(utf8_array, array_len, strobj.CharAddr(0), len); | 9981 Utf8::DecodeToAscii(utf8_array, array_len, |
| 9982 OneByteString::CharAddr(strobj, 0), len); |
| 9943 } | 9983 } |
| 9944 return strobj.raw(); | 9984 return strobj.raw(); |
| 9945 } | 9985 } |
| 9946 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP)); | 9986 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP)); |
| 9947 const TwoByteString& strobj = | 9987 const String& strobj = String::Handle(TwoByteString::New(len, space)); |
| 9948 TwoByteString::Handle(TwoByteString::New(len, space)); | |
| 9949 NoGCScope no_gc; | 9988 NoGCScope no_gc; |
| 9950 Utf8::DecodeToUTF16(utf8_array, array_len, strobj.CharAddr(0), len); | 9989 Utf8::DecodeToUTF16(utf8_array, array_len, |
| 9990 TwoByteString::CharAddr(strobj, 0), len); |
| 9951 return strobj.raw(); | 9991 return strobj.raw(); |
| 9952 } | 9992 } |
| 9953 | 9993 |
| 9954 | 9994 |
| 9955 RawString* String::New(const uint16_t* utf16_array, | 9995 RawString* String::New(const uint16_t* utf16_array, |
| 9956 intptr_t array_len, | 9996 intptr_t array_len, |
| 9957 Heap::Space space) { | 9997 Heap::Space space) { |
| 9958 bool is_one_byte_string = true; | 9998 bool is_one_byte_string = true; |
| 9959 for (intptr_t i = 0; i < array_len; ++i) { | 9999 for (intptr_t i = 0; i < array_len; ++i) { |
| 9960 if (utf16_array[i] > 0x7F) { | 10000 if (utf16_array[i] > 0x7F) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10026 } | 10066 } |
| 10027 | 10067 |
| 10028 | 10068 |
| 10029 void String::Copy(const String& dst, intptr_t dst_offset, | 10069 void String::Copy(const String& dst, intptr_t dst_offset, |
| 10030 const uint8_t* characters, | 10070 const uint8_t* characters, |
| 10031 intptr_t len) { | 10071 intptr_t len) { |
| 10032 ASSERT(dst_offset >= 0); | 10072 ASSERT(dst_offset >= 0); |
| 10033 ASSERT(len >= 0); | 10073 ASSERT(len >= 0); |
| 10034 ASSERT(len <= (dst.Length() - dst_offset)); | 10074 ASSERT(len <= (dst.Length() - dst_offset)); |
| 10035 if (dst.IsOneByteString()) { | 10075 if (dst.IsOneByteString()) { |
| 10036 const OneByteString& onestr = OneByteString::Cast(dst); | |
| 10037 NoGCScope no_gc; | 10076 NoGCScope no_gc; |
| 10038 if (len > 0) { | 10077 if (len > 0) { |
| 10039 memmove(onestr.CharAddr(dst_offset), characters, len); | 10078 memmove(OneByteString::CharAddr(dst, dst_offset), |
| 10079 characters, |
| 10080 len); |
| 10040 } | 10081 } |
| 10041 } else if (dst.IsTwoByteString()) { | 10082 } else if (dst.IsTwoByteString()) { |
| 10042 const TwoByteString& twostr = TwoByteString::Cast(dst); | |
| 10043 NoGCScope no_gc; | |
| 10044 for (intptr_t i = 0; i < len; ++i) { | 10083 for (intptr_t i = 0; i < len; ++i) { |
| 10045 *twostr.CharAddr(i + dst_offset) = characters[i]; | 10084 *TwoByteString::CharAddr(dst, i + dst_offset) = characters[i]; |
| 10046 } | 10085 } |
| 10047 } | 10086 } |
| 10048 } | 10087 } |
| 10049 | 10088 |
| 10050 | 10089 |
| 10051 void String::Copy(const String& dst, intptr_t dst_offset, | 10090 void String::Copy(const String& dst, intptr_t dst_offset, |
| 10052 const uint16_t* utf16_array, | 10091 const uint16_t* utf16_array, |
| 10053 intptr_t array_len) { | 10092 intptr_t array_len) { |
| 10054 ASSERT(dst_offset >= 0); | 10093 ASSERT(dst_offset >= 0); |
| 10055 ASSERT(array_len >= 0); | 10094 ASSERT(array_len >= 0); |
| 10056 ASSERT(array_len <= (dst.Length() - dst_offset)); | 10095 ASSERT(array_len <= (dst.Length() - dst_offset)); |
| 10057 if (dst.IsOneByteString()) { | 10096 if (dst.IsOneByteString()) { |
| 10058 const OneByteString& onestr = OneByteString::Cast(dst); | |
| 10059 NoGCScope no_gc; | 10097 NoGCScope no_gc; |
| 10060 for (intptr_t i = 0; i < array_len; ++i) { | 10098 for (intptr_t i = 0; i < array_len; ++i) { |
| 10061 ASSERT(utf16_array[i] <= 0x7F); | 10099 ASSERT(utf16_array[i] <= 0x7F); |
| 10062 *onestr.CharAddr(i + dst_offset) = utf16_array[i]; | 10100 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i]; |
| 10063 } | 10101 } |
| 10064 } else { | 10102 } else { |
| 10065 ASSERT(dst.IsTwoByteString()); | 10103 ASSERT(dst.IsTwoByteString()); |
| 10066 const TwoByteString& twostr = TwoByteString::Cast(dst); | |
| 10067 NoGCScope no_gc; | 10104 NoGCScope no_gc; |
| 10068 if (array_len > 0) { | 10105 if (array_len > 0) { |
| 10069 memmove(twostr.CharAddr(dst_offset), utf16_array, (array_len * 2)); | 10106 memmove(TwoByteString::CharAddr(dst, dst_offset), |
| 10107 utf16_array, |
| 10108 array_len * 2); |
| 10070 } | 10109 } |
| 10071 } | 10110 } |
| 10072 } | 10111 } |
| 10073 | 10112 |
| 10074 | 10113 |
| 10075 void String::Copy(const String& dst, intptr_t dst_offset, | 10114 void String::Copy(const String& dst, intptr_t dst_offset, |
| 10076 const String& src, intptr_t src_offset, | 10115 const String& src, intptr_t src_offset, |
| 10077 intptr_t len) { | 10116 intptr_t len) { |
| 10078 ASSERT(dst_offset >= 0); | 10117 ASSERT(dst_offset >= 0); |
| 10079 ASSERT(src_offset >= 0); | 10118 ASSERT(src_offset >= 0); |
| 10080 ASSERT(len >= 0); | 10119 ASSERT(len >= 0); |
| 10081 ASSERT(len <= (dst.Length() - dst_offset)); | 10120 ASSERT(len <= (dst.Length() - dst_offset)); |
| 10082 ASSERT(len <= (src.Length() - src_offset)); | 10121 ASSERT(len <= (src.Length() - src_offset)); |
| 10083 if (len > 0) { | 10122 if (len > 0) { |
| 10084 intptr_t char_size = src.CharSize(); | 10123 intptr_t char_size = src.CharSize(); |
| 10085 if (char_size == kOneByteChar) { | 10124 if (char_size == kOneByteChar) { |
| 10086 if (src.IsOneByteString()) { | 10125 if (src.IsOneByteString()) { |
| 10087 const OneByteString& onestr = OneByteString::Cast(src); | |
| 10088 NoGCScope no_gc; | 10126 NoGCScope no_gc; |
| 10089 String::Copy(dst, dst_offset, onestr.CharAddr(0) + src_offset, len); | 10127 String::Copy(dst, |
| 10128 dst_offset, |
| 10129 OneByteString::CharAddr(src, src_offset), |
| 10130 len); |
| 10090 } else { | 10131 } else { |
| 10091 ASSERT(src.IsExternalOneByteString()); | 10132 ASSERT(src.IsExternalOneByteString()); |
| 10092 const ExternalOneByteString& onestr = ExternalOneByteString::Cast(src); | |
| 10093 NoGCScope no_gc; | 10133 NoGCScope no_gc; |
| 10094 String::Copy(dst, dst_offset, onestr.CharAddr(0) + src_offset, len); | 10134 String::Copy(dst, |
| 10135 dst_offset, |
| 10136 ExternalOneByteString::CharAddr(src, src_offset), |
| 10137 len); |
| 10095 } | 10138 } |
| 10096 } else { | 10139 } else { |
| 10097 ASSERT(char_size == kTwoByteChar); | 10140 ASSERT(char_size == kTwoByteChar); |
| 10098 if (src.IsTwoByteString()) { | 10141 if (src.IsTwoByteString()) { |
| 10099 const TwoByteString& twostr = TwoByteString::Cast(src); | |
| 10100 NoGCScope no_gc; | 10142 NoGCScope no_gc; |
| 10101 String::Copy(dst, dst_offset, twostr.CharAddr(0) + src_offset, len); | 10143 String::Copy(dst, |
| 10144 dst_offset, |
| 10145 TwoByteString::CharAddr(src, src_offset), |
| 10146 len); |
| 10102 } else { | 10147 } else { |
| 10103 ASSERT(src.IsExternalTwoByteString()); | 10148 ASSERT(src.IsExternalTwoByteString()); |
| 10104 const ExternalTwoByteString& twostr = ExternalTwoByteString::Cast(src); | |
| 10105 NoGCScope no_gc; | 10149 NoGCScope no_gc; |
| 10106 String::Copy(dst, dst_offset, twostr.CharAddr(0) + src_offset, len); | 10150 String::Copy(dst, |
| 10151 dst_offset, |
| 10152 ExternalTwoByteString::CharAddr(src, src_offset), |
| 10153 len); |
| 10107 } | 10154 } |
| 10108 } | 10155 } |
| 10109 } | 10156 } |
| 10110 } | 10157 } |
| 10111 | 10158 |
| 10112 | 10159 |
| 10113 RawString* String::EscapeSpecialCharacters(const String& str, bool raw_str) { | 10160 RawString* String::EscapeSpecialCharacters(const String& str, bool raw_str) { |
| 10114 if (str.IsOneByteString()) { | 10161 if (str.IsOneByteString()) { |
| 10115 const OneByteString& onestr = OneByteString::Cast(str); | 10162 return OneByteString::EscapeSpecialCharacters(str, raw_str); |
| 10116 return onestr.EscapeSpecialCharacters(raw_str); | |
| 10117 } | 10163 } |
| 10118 ASSERT(str.IsTwoByteString()); | 10164 ASSERT(str.IsTwoByteString()); |
| 10119 const TwoByteString& twostr = TwoByteString::Cast(str); | 10165 return TwoByteString::EscapeSpecialCharacters(str, raw_str); |
| 10120 return twostr.EscapeSpecialCharacters(raw_str); | |
| 10121 } | 10166 } |
| 10122 | 10167 |
| 10123 | 10168 |
| 10124 RawString* String::NewFormatted(const char* format, ...) { | 10169 RawString* String::NewFormatted(const char* format, ...) { |
| 10125 va_list args; | 10170 va_list args; |
| 10126 va_start(args, format); | 10171 va_start(args, format); |
| 10127 RawString* result = NewFormattedV(format, args); | 10172 RawString* result = NewFormattedV(format, args); |
| 10128 NoGCScope no_gc; | 10173 NoGCScope no_gc; |
| 10129 va_end(args); | 10174 va_end(args); |
| 10130 return result; | 10175 return result; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10227 Zone* zone = Isolate::Current()->current_zone(); | 10272 Zone* zone = Isolate::Current()->current_zone(); |
| 10228 uint8_t* result = zone->Alloc<uint8_t>(len + 1); | 10273 uint8_t* result = zone->Alloc<uint8_t>(len + 1); |
| 10229 ToUTF8(result, len); | 10274 ToUTF8(result, len); |
| 10230 result[len] = 0; | 10275 result[len] = 0; |
| 10231 return reinterpret_cast<const char*>(result); | 10276 return reinterpret_cast<const char*>(result); |
| 10232 } | 10277 } |
| 10233 | 10278 |
| 10234 | 10279 |
| 10235 void String::ToUTF8(uint8_t* utf8_array, intptr_t array_len) const { | 10280 void String::ToUTF8(uint8_t* utf8_array, intptr_t array_len) const { |
| 10236 if (CharSize() == kOneByteChar) { | 10281 if (CharSize() == kOneByteChar) { |
| 10237 const OneByteString& obj = OneByteString::Cast(*this); | 10282 const String& obj = *this; |
| 10238 ASSERT(array_len >= obj.Length()); | 10283 ASSERT(array_len >= obj.Length()); |
| 10239 if (obj.Length() > 0) { | 10284 if (obj.Length() > 0) { |
| 10240 memmove(utf8_array, obj.CharAddr(0), obj.Length()); | 10285 memmove(utf8_array, OneByteString::CharAddr(obj, 0), obj.Length()); |
| 10241 } | 10286 } |
| 10242 } else { | 10287 } else { |
| 10243 ASSERT(array_len >= Utf8::Length(*this)); | 10288 ASSERT(array_len >= Utf8::Length(*this)); |
| 10244 Utf8::Encode(*this, reinterpret_cast<char*>(utf8_array), array_len); | 10289 Utf8::Encode(*this, reinterpret_cast<char*>(utf8_array), array_len); |
| 10245 } | 10290 } |
| 10246 } | 10291 } |
| 10247 | 10292 |
| 10248 | 10293 |
| 10249 RawString* String::Transform(int32_t (*mapping)(int32_t ch), | 10294 RawString* String::Transform(int32_t (*mapping)(int32_t ch), |
| 10250 const String& str, | 10295 const String& str, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 10278 return Transform(CaseMapping::ToUpper, str, space); | 10323 return Transform(CaseMapping::ToUpper, str, space); |
| 10279 } | 10324 } |
| 10280 | 10325 |
| 10281 | 10326 |
| 10282 RawString* String::ToLowerCase(const String& str, Heap::Space space) { | 10327 RawString* String::ToLowerCase(const String& str, Heap::Space space) { |
| 10283 // TODO(cshapiro): create a fast-path for OneByteString instances. | 10328 // TODO(cshapiro): create a fast-path for OneByteString instances. |
| 10284 return Transform(CaseMapping::ToLower, str, space); | 10329 return Transform(CaseMapping::ToLower, str, space); |
| 10285 } | 10330 } |
| 10286 | 10331 |
| 10287 | 10332 |
| 10288 RawOneByteString* OneByteString::EscapeSpecialCharacters(bool raw_str) const { | 10333 RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str, |
| 10289 intptr_t len = Length(); | 10334 bool raw_str) { |
| 10335 intptr_t len = str.Length(); |
| 10290 if (len > 0) { | 10336 if (len > 0) { |
| 10291 intptr_t num_escapes = 0; | 10337 intptr_t num_escapes = 0; |
| 10292 intptr_t index = 0; | 10338 intptr_t index = 0; |
| 10293 for (intptr_t i = 0; i < len; i++) { | 10339 for (intptr_t i = 0; i < len; i++) { |
| 10294 if (IsSpecialCharacter(*CharAddr(i)) || | 10340 if (IsSpecialCharacter(*CharAddr(str, i)) || |
| 10295 (!raw_str && (*CharAddr(i) == '\\'))) { | 10341 (!raw_str && (*CharAddr(str, i) == '\\'))) { |
| 10296 num_escapes += 1; | 10342 num_escapes += 1; |
| 10297 } | 10343 } |
| 10298 } | 10344 } |
| 10299 const OneByteString& dststr = OneByteString::Handle( | 10345 const String& dststr = String::Handle( |
| 10300 OneByteString::New(len + num_escapes, Heap::kNew)); | 10346 OneByteString::New(len + num_escapes, Heap::kNew)); |
| 10301 for (intptr_t i = 0; i < len; i++) { | 10347 for (intptr_t i = 0; i < len; i++) { |
| 10302 if (IsSpecialCharacter(*CharAddr(i))) { | 10348 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 10303 *(dststr.CharAddr(index)) = '\\'; | 10349 *(CharAddr(dststr, index)) = '\\'; |
| 10304 *(dststr.CharAddr(index + 1)) = SpecialCharacter(*CharAddr(i)); | 10350 *(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i)); |
| 10305 index += 2; | 10351 index += 2; |
| 10306 } else if (!raw_str && (*CharAddr(i) == '\\')) { | 10352 } else if (!raw_str && (*CharAddr(str, i) == '\\')) { |
| 10307 *(dststr.CharAddr(index)) = '\\'; | 10353 *(CharAddr(dststr, index)) = '\\'; |
| 10308 *(dststr.CharAddr(index + 1)) = '\\'; | 10354 *(CharAddr(dststr, index + 1)) = '\\'; |
| 10309 index += 2; | 10355 index += 2; |
| 10310 } else { | 10356 } else { |
| 10311 *(dststr.CharAddr(index)) = *CharAddr(i); | 10357 *(CharAddr(dststr, index)) = *CharAddr(str, i); |
| 10312 index += 1; | 10358 index += 1; |
| 10313 } | 10359 } |
| 10314 } | 10360 } |
| 10315 return dststr.raw(); | 10361 return OneByteString::raw(dststr); |
| 10316 } | 10362 } |
| 10317 return OneByteString::null(); | 10363 return OneByteString::null(); |
| 10318 } | 10364 } |
| 10319 | 10365 |
| 10320 | 10366 |
| 10321 // Check to see if 'name' matches 'this' as is or | 10367 // Check to see if 'str1' matches 'str2' as is or |
| 10322 // once the private key separator is stripped from name. | 10368 // once the private key separator is stripped from str2. |
| 10323 // | 10369 // |
| 10324 // Things are made more complicated by the fact that constructors are | 10370 // Things are made more complicated by the fact that constructors are |
| 10325 // added *after* the private suffix, so "foo@123.named" should match | 10371 // added *after* the private suffix, so "foo@123.named" should match |
| 10326 // "foo.named". | 10372 // "foo.named". |
| 10327 // | 10373 // |
| 10328 // Also, the private suffix can occur more than once in the name, as in: | 10374 // Also, the private suffix can occur more than once in the name, as in: |
| 10329 // | 10375 // |
| 10330 // _ReceivePortImpl@6be832b._internal@6be832b | 10376 // _ReceivePortImpl@6be832b._internal@6be832b |
| 10331 // | 10377 // |
| 10332 bool OneByteString::EqualsIgnoringPrivateKey(const OneByteString& name) const { | 10378 bool OneByteString::EqualsIgnoringPrivateKey(const String& str1, |
| 10333 if (raw() == name.raw()) { | 10379 const String& str2) { |
| 10380 ASSERT(str2.IsOneByteString()); |
| 10381 if (str1.raw() == str2.raw()) { |
| 10334 return true; // Both handles point to the same raw instance. | 10382 return true; // Both handles point to the same raw instance. |
| 10335 } | 10383 } |
| 10336 intptr_t len = Length(); | 10384 NoGCScope no_gc; |
| 10337 intptr_t name_len = name.Length(); | 10385 intptr_t len = str1.Length(); |
| 10338 if (len == name_len) { | 10386 intptr_t str2_len = str2.Length(); |
| 10387 if (len == str2_len) { |
| 10339 for (intptr_t i = 0; i < len; i++) { | 10388 for (intptr_t i = 0; i < len; i++) { |
| 10340 if (*(CharAddr(i)) != *(name.CharAddr(i))) { | 10389 if (*CharAddr(str1, i) != *CharAddr(str2, i)) { |
| 10341 return false; | 10390 return false; |
| 10342 } | 10391 } |
| 10343 } | 10392 } |
| 10344 return true; | 10393 return true; |
| 10345 } | 10394 } |
| 10346 if (len < name_len) { | 10395 if (len < str2_len) { |
| 10347 return false; // No way they can match. | 10396 return false; // No way they can match. |
| 10348 } | 10397 } |
| 10349 intptr_t pos = 0; | 10398 intptr_t pos = 0; |
| 10350 intptr_t name_pos = 0; | 10399 intptr_t str2_pos = 0; |
| 10351 while (pos < len) { | 10400 while (pos < len) { |
| 10352 int32_t ch = *(CharAddr(pos)); | 10401 int32_t ch = *CharAddr(str1, pos); |
| 10353 pos++; | 10402 pos++; |
| 10354 | 10403 |
| 10355 if (ch == Scanner::kPrivateKeySeparator) { | 10404 if (ch == Scanner::kPrivateKeySeparator) { |
| 10356 // Consume a private key separator. | 10405 // Consume a private key separator. |
| 10357 while (pos < len && *(CharAddr(pos)) != '.') { | 10406 while ((pos < len) && (*CharAddr(str1, pos) != '.')) { |
| 10358 pos++; | 10407 pos++; |
| 10359 } | 10408 } |
| 10360 // Resume matching characters. | 10409 // Resume matching characters. |
| 10361 continue; | 10410 continue; |
| 10362 } | 10411 } |
| 10363 if (name_pos == name_len || ch != *(name.CharAddr(name_pos))) { | 10412 if ((str2_pos == str2_len) || (ch != *CharAddr(str2, str2_pos))) { |
| 10364 return false; | 10413 return false; |
| 10365 } | 10414 } |
| 10366 name_pos++; | 10415 str2_pos++; |
| 10367 } | 10416 } |
| 10368 | 10417 |
| 10369 // We have reached the end of mangled_name string. | 10418 // We have reached the end of mangled_name string. |
| 10370 ASSERT(pos == len); | 10419 ASSERT(pos == len); |
| 10371 return (name_pos == name_len); | 10420 return (str2_pos == str2_len); |
| 10372 } | 10421 } |
| 10373 | 10422 |
| 10374 | 10423 |
| 10375 RawOneByteString* OneByteString::New(intptr_t len, | 10424 RawOneByteString* OneByteString::New(intptr_t len, |
| 10376 Heap::Space space) { | 10425 Heap::Space space) { |
| 10377 ASSERT(Isolate::Current() == Dart::vm_isolate() || | 10426 ASSERT(Isolate::Current() == Dart::vm_isolate() || |
| 10378 Isolate::Current()->object_store()->one_byte_string_class() != | 10427 Isolate::Current()->object_store()->one_byte_string_class() != |
| 10379 Class::null()); | 10428 Class::null()); |
| 10380 if (len < 0 || len > kMaxElements) { | 10429 if (len < 0 || len > kMaxElements) { |
| 10381 // This should be caught before we reach here. | 10430 // This should be caught before we reach here. |
| 10382 FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len); | 10431 FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len); |
| 10383 } | 10432 } |
| 10384 OneByteString& result = OneByteString::Handle(); | 10433 String& result = String::Handle(); |
| 10385 { | 10434 { |
| 10386 RawObject* raw = Object::Allocate(OneByteString::kClassId, | 10435 RawObject* raw = Object::Allocate(OneByteString::kClassId, |
| 10387 OneByteString::InstanceSize(len), | 10436 OneByteString::InstanceSize(len), |
| 10388 space); | 10437 space); |
| 10389 NoGCScope no_gc; | 10438 NoGCScope no_gc; |
| 10390 result ^= raw; | 10439 result ^= raw; |
| 10391 result.SetLength(len); | 10440 result.SetLength(len); |
| 10392 result.SetHash(0); | 10441 result.SetHash(0); |
| 10393 } | 10442 } |
| 10394 return result.raw(); | 10443 return OneByteString::raw(result); |
| 10395 } | 10444 } |
| 10396 | 10445 |
| 10397 | 10446 |
| 10398 RawOneByteString* OneByteString::New(const uint8_t* characters, | 10447 RawOneByteString* OneByteString::New(const uint8_t* characters, |
| 10399 intptr_t len, | 10448 intptr_t len, |
| 10400 Heap::Space space) { | 10449 Heap::Space space) { |
| 10401 const OneByteString& result = | 10450 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10402 OneByteString::Handle(OneByteString::New(len, space)); | |
| 10403 if (len > 0) { | 10451 if (len > 0) { |
| 10404 NoGCScope no_gc; | 10452 NoGCScope no_gc; |
| 10405 memmove(result.CharAddr(0), characters, len); | 10453 memmove(CharAddr(result, 0), characters, len); |
| 10406 } | 10454 } |
| 10407 return result.raw(); | 10455 return OneByteString::raw(result); |
| 10408 } | 10456 } |
| 10409 | 10457 |
| 10410 | 10458 |
| 10411 RawOneByteString* OneByteString::New(const uint16_t* characters, | 10459 RawOneByteString* OneByteString::New(const uint16_t* characters, |
| 10412 intptr_t len, | 10460 intptr_t len, |
| 10413 Heap::Space space) { | 10461 Heap::Space space) { |
| 10414 const OneByteString& result = | 10462 const String& result =String::Handle(OneByteString::New(len, space)); |
| 10415 OneByteString::Handle(OneByteString::New(len, space)); | |
| 10416 for (intptr_t i = 0; i < len; ++i) { | 10463 for (intptr_t i = 0; i < len; ++i) { |
| 10417 ASSERT(characters[i] <= 0x7F); | 10464 ASSERT(characters[i] <= 0x7F); |
| 10418 *result.CharAddr(i) = characters[i]; | 10465 *CharAddr(result, i) = characters[i]; |
| 10419 } | 10466 } |
| 10420 return result.raw(); | 10467 return OneByteString::raw(result); |
| 10421 } | 10468 } |
| 10422 | 10469 |
| 10423 | 10470 |
| 10424 RawOneByteString* OneByteString::New(const uint32_t* characters, | 10471 RawOneByteString* OneByteString::New(const uint32_t* characters, |
| 10425 intptr_t len, | 10472 intptr_t len, |
| 10426 Heap::Space space) { | 10473 Heap::Space space) { |
| 10427 const OneByteString& result = | 10474 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10428 OneByteString::Handle(OneByteString::New(len, space)); | |
| 10429 for (intptr_t i = 0; i < len; ++i) { | 10475 for (intptr_t i = 0; i < len; ++i) { |
| 10430 ASSERT(characters[i] <= 0x7F); | 10476 ASSERT(characters[i] <= 0x7F); |
| 10431 *result.CharAddr(i) = characters[i]; | 10477 *CharAddr(result, i) = characters[i]; |
| 10432 } | 10478 } |
| 10433 return result.raw(); | 10479 return OneByteString::raw(result); |
| 10434 } | 10480 } |
| 10435 | 10481 |
| 10436 | 10482 |
| 10437 RawOneByteString* OneByteString::New(const OneByteString& str, | 10483 RawOneByteString* OneByteString::New(const String& str, |
| 10438 Heap::Space space) { | 10484 Heap::Space space) { |
| 10439 intptr_t len = str.Length(); | 10485 intptr_t len = str.Length(); |
| 10440 const OneByteString& result = | 10486 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10441 OneByteString::Handle(OneByteString::New(len, space)); | |
| 10442 String::Copy(result, 0, str, 0, len); | 10487 String::Copy(result, 0, str, 0, len); |
| 10443 return result.raw(); | 10488 return OneByteString::raw(result); |
| 10444 } | 10489 } |
| 10445 | 10490 |
| 10446 | 10491 |
| 10447 RawOneByteString* OneByteString::Concat(const String& str1, | 10492 RawOneByteString* OneByteString::Concat(const String& str1, |
| 10448 const String& str2, | 10493 const String& str2, |
| 10449 Heap::Space space) { | 10494 Heap::Space space) { |
| 10450 intptr_t len1 = str1.Length(); | 10495 intptr_t len1 = str1.Length(); |
| 10451 intptr_t len2 = str2.Length(); | 10496 intptr_t len2 = str2.Length(); |
| 10452 intptr_t len = len1 + len2; | 10497 intptr_t len = len1 + len2; |
| 10453 const OneByteString& result = | 10498 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10454 OneByteString::Handle(OneByteString::New(len, space)); | |
| 10455 String::Copy(result, 0, str1, 0, len1); | 10499 String::Copy(result, 0, str1, 0, len1); |
| 10456 String::Copy(result, len1, str2, 0, len2); | 10500 String::Copy(result, len1, str2, 0, len2); |
| 10457 return result.raw(); | 10501 return OneByteString::raw(result); |
| 10458 } | 10502 } |
| 10459 | 10503 |
| 10460 | 10504 |
| 10461 RawOneByteString* OneByteString::ConcatAll(const Array& strings, | 10505 RawOneByteString* OneByteString::ConcatAll(const Array& strings, |
| 10462 intptr_t len, | 10506 intptr_t len, |
| 10463 Heap::Space space) { | 10507 Heap::Space space) { |
| 10464 const OneByteString& result = | 10508 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10465 OneByteString::Handle(OneByteString::New(len, space)); | 10509 String& str = String::Handle(); |
| 10466 OneByteString& str = OneByteString::Handle(); | |
| 10467 intptr_t strings_len = strings.Length(); | 10510 intptr_t strings_len = strings.Length(); |
| 10468 intptr_t pos = 0; | 10511 intptr_t pos = 0; |
| 10469 for (intptr_t i = 0; i < strings_len; i++) { | 10512 for (intptr_t i = 0; i < strings_len; i++) { |
| 10470 str ^= strings.At(i); | 10513 str ^= strings.At(i); |
| 10471 intptr_t str_len = str.Length(); | 10514 intptr_t str_len = str.Length(); |
| 10472 String::Copy(result, pos, str, 0, str_len); | 10515 String::Copy(result, pos, str, 0, str_len); |
| 10473 pos += str_len; | 10516 pos += str_len; |
| 10474 } | 10517 } |
| 10475 return result.raw(); | 10518 return OneByteString::raw(result); |
| 10476 } | 10519 } |
| 10477 | 10520 |
| 10478 | 10521 |
| 10479 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), | 10522 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), |
| 10480 const String& str, | 10523 const String& str, |
| 10481 Heap::Space space) { | 10524 Heap::Space space) { |
| 10482 ASSERT(!str.IsNull()); | 10525 ASSERT(!str.IsNull()); |
| 10483 intptr_t len = str.Length(); | 10526 intptr_t len = str.Length(); |
| 10484 const OneByteString& result = | 10527 const String& result = String::Handle(OneByteString::New(len, space)); |
| 10485 OneByteString::Handle(OneByteString::New(len, space)); | |
| 10486 for (intptr_t i = 0; i < len; ++i) { | 10528 for (intptr_t i = 0; i < len; ++i) { |
| 10487 int32_t ch = mapping(str.CharAt(i)); | 10529 int32_t ch = mapping(str.CharAt(i)); |
| 10488 ASSERT(ch >= 0 && ch <= 0x7F); | 10530 ASSERT(ch >= 0 && ch <= 0x7F); |
| 10489 *result.CharAddr(i) = ch; | 10531 *CharAddr(result, i) = ch; |
| 10490 } | 10532 } |
| 10491 return result.raw(); | 10533 return OneByteString::raw(result); |
| 10492 } | 10534 } |
| 10493 | 10535 |
| 10494 | 10536 |
| 10495 const char* OneByteString::ToCString() const { | 10537 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str, |
| 10496 return String::ToCString(); | 10538 bool raw_str) { |
| 10497 } | 10539 intptr_t len = str.Length(); |
| 10498 | |
| 10499 | |
| 10500 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(bool raw_str) const { | |
| 10501 intptr_t len = Length(); | |
| 10502 if (len > 0) { | 10540 if (len > 0) { |
| 10503 intptr_t num_escapes = 0; | 10541 intptr_t num_escapes = 0; |
| 10504 intptr_t index = 0; | 10542 intptr_t index = 0; |
| 10505 for (intptr_t i = 0; i < len; i++) { | 10543 for (intptr_t i = 0; i < len; i++) { |
| 10506 if (IsSpecialCharacter(*CharAddr(i)) || | 10544 if (IsSpecialCharacter(*CharAddr(str, i)) || |
| 10507 (!raw_str && (*CharAddr(i) == '\\'))) { | 10545 (!raw_str && (*CharAddr(str, i) == '\\'))) { |
| 10508 num_escapes += 1; | 10546 num_escapes += 1; |
| 10509 } | 10547 } |
| 10510 } | 10548 } |
| 10511 const TwoByteString& dststr = TwoByteString::Handle( | 10549 const String& dststr = String::Handle( |
| 10512 TwoByteString::New(len + num_escapes, Heap::kNew)); | 10550 TwoByteString::New(len + num_escapes, Heap::kNew)); |
| 10513 for (intptr_t i = 0; i < len; i++) { | 10551 for (intptr_t i = 0; i < len; i++) { |
| 10514 if (IsSpecialCharacter(*CharAddr(i))) { | 10552 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 10515 *(dststr.CharAddr(index)) = '\\'; | 10553 *(CharAddr(dststr, index)) = '\\'; |
| 10516 *(dststr.CharAddr(index + 1)) = SpecialCharacter(*CharAddr(i)); | 10554 *(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i)); |
| 10517 index += 2; | 10555 index += 2; |
| 10518 } else if (!raw_str && (*CharAddr(i) == '\\')) { | 10556 } else if (!raw_str && (*CharAddr(str, i) == '\\')) { |
| 10519 *(dststr.CharAddr(index)) = '\\'; | 10557 *(CharAddr(dststr, index)) = '\\'; |
| 10520 *(dststr.CharAddr(index + 1)) = '\\'; | 10558 *(CharAddr(dststr, index + 1)) = '\\'; |
| 10521 index += 2; | 10559 index += 2; |
| 10522 } else { | 10560 } else { |
| 10523 *(dststr.CharAddr(index)) = *CharAddr(i); | 10561 *(CharAddr(dststr, index)) = *CharAddr(str, i); |
| 10524 index += 1; | 10562 index += 1; |
| 10525 } | 10563 } |
| 10526 } | 10564 } |
| 10527 return dststr.raw(); | 10565 return TwoByteString::raw(dststr); |
| 10528 } | 10566 } |
| 10529 return TwoByteString::null(); | 10567 return TwoByteString::null(); |
| 10530 } | 10568 } |
| 10531 | 10569 |
| 10532 | 10570 |
| 10533 RawTwoByteString* TwoByteString::New(intptr_t len, | 10571 RawTwoByteString* TwoByteString::New(intptr_t len, |
| 10534 Heap::Space space) { | 10572 Heap::Space space) { |
| 10535 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); | 10573 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); |
| 10536 if (len < 0 || len > kMaxElements) { | 10574 if (len < 0 || len > kMaxElements) { |
| 10537 // This should be caught before we reach here. | 10575 // This should be caught before we reach here. |
| 10538 FATAL1("Fatal error in TwoByteString::New: invalid len %"Pd"\n", len); | 10576 FATAL1("Fatal error in TwoByteString::New: invalid len %"Pd"\n", len); |
| 10539 } | 10577 } |
| 10540 TwoByteString& result = TwoByteString::Handle(); | 10578 String& result = String::Handle(); |
| 10541 { | 10579 { |
| 10542 RawObject* raw = Object::Allocate(TwoByteString::kClassId, | 10580 RawObject* raw = Object::Allocate(TwoByteString::kClassId, |
| 10543 TwoByteString::InstanceSize(len), | 10581 TwoByteString::InstanceSize(len), |
| 10544 space); | 10582 space); |
| 10545 NoGCScope no_gc; | 10583 NoGCScope no_gc; |
| 10546 result ^= raw; | 10584 result ^= raw; |
| 10547 result.SetLength(len); | 10585 result.SetLength(len); |
| 10548 result.SetHash(0); | 10586 result.SetHash(0); |
| 10549 } | 10587 } |
| 10550 return result.raw(); | 10588 return TwoByteString::raw(result); |
| 10551 } | 10589 } |
| 10552 | 10590 |
| 10553 | 10591 |
| 10554 RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array, | 10592 RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array, |
| 10555 intptr_t array_len, | 10593 intptr_t array_len, |
| 10556 Heap::Space space) { | 10594 Heap::Space space) { |
| 10557 ASSERT(array_len > 0); | 10595 ASSERT(array_len > 0); |
| 10558 const TwoByteString& result = | 10596 const String& result = String::Handle(TwoByteString::New(array_len, space)); |
| 10559 TwoByteString::Handle(TwoByteString::New(array_len, space)); | |
| 10560 { | 10597 { |
| 10561 NoGCScope no_gc; | 10598 NoGCScope no_gc; |
| 10562 memmove(result.CharAddr(0), utf16_array, (array_len * 2)); | 10599 memmove(CharAddr(result, 0), utf16_array, (array_len * 2)); |
| 10563 } | 10600 } |
| 10564 return result.raw(); | 10601 return TwoByteString::raw(result); |
| 10565 } | 10602 } |
| 10566 | 10603 |
| 10567 | 10604 |
| 10568 RawTwoByteString* TwoByteString::New(intptr_t utf16_len, | 10605 RawTwoByteString* TwoByteString::New(intptr_t utf16_len, |
| 10569 const uint32_t* utf32_array, | 10606 const uint32_t* utf32_array, |
| 10570 intptr_t array_len, | 10607 intptr_t array_len, |
| 10571 Heap::Space space) { | 10608 Heap::Space space) { |
| 10572 ASSERT((array_len > 0) && (utf16_len >= array_len)); | 10609 ASSERT((array_len > 0) && (utf16_len >= array_len)); |
| 10573 const TwoByteString& result = | 10610 const String& result = String::Handle(TwoByteString::New(utf16_len, space)); |
| 10574 TwoByteString::Handle(TwoByteString::New(utf16_len, space)); | |
| 10575 { | 10611 { |
| 10576 NoGCScope no_gc; | 10612 NoGCScope no_gc; |
| 10577 intptr_t j = 0; | 10613 intptr_t j = 0; |
| 10578 for (intptr_t i = 0; i < array_len; ++i) { | 10614 for (intptr_t i = 0; i < array_len; ++i) { |
| 10579 if (utf32_array[i] > 0xffff) { | 10615 if (utf32_array[i] > 0xffff) { |
| 10580 ASSERT(j < (utf16_len - 1)); | 10616 ASSERT(j < (utf16_len - 1)); |
| 10581 Utf8::ConvertUTF32ToUTF16(utf32_array[i], result.CharAddr(j)); | 10617 Utf8::ConvertUTF32ToUTF16(utf32_array[i], CharAddr(result, j)); |
| 10582 j += 2; | 10618 j += 2; |
| 10583 } else { | 10619 } else { |
| 10584 ASSERT(j < utf16_len); | 10620 ASSERT(j < utf16_len); |
| 10585 *result.CharAddr(j) = utf32_array[i]; | 10621 *CharAddr(result, j) = utf32_array[i]; |
| 10586 j += 1; | 10622 j += 1; |
| 10587 } | 10623 } |
| 10588 } | 10624 } |
| 10589 } | 10625 } |
| 10590 return result.raw(); | 10626 return TwoByteString::raw(result); |
| 10591 } | 10627 } |
| 10592 | 10628 |
| 10593 | 10629 |
| 10594 RawTwoByteString* TwoByteString::New(const TwoByteString& str, | 10630 RawTwoByteString* TwoByteString::New(const String& str, |
| 10595 Heap::Space space) { | 10631 Heap::Space space) { |
| 10596 intptr_t len = str.Length(); | 10632 intptr_t len = str.Length(); |
| 10597 const TwoByteString& result = | 10633 const String& result = String::Handle(TwoByteString::New(len, space)); |
| 10598 TwoByteString::Handle(TwoByteString::New(len, space)); | |
| 10599 String::Copy(result, 0, str, 0, len); | 10634 String::Copy(result, 0, str, 0, len); |
| 10600 return result.raw(); | 10635 return TwoByteString::raw(result); |
| 10601 } | 10636 } |
| 10602 | 10637 |
| 10603 | 10638 |
| 10604 RawTwoByteString* TwoByteString::Concat(const String& str1, | 10639 RawTwoByteString* TwoByteString::Concat(const String& str1, |
| 10605 const String& str2, | 10640 const String& str2, |
| 10606 Heap::Space space) { | 10641 Heap::Space space) { |
| 10607 intptr_t len1 = str1.Length(); | 10642 intptr_t len1 = str1.Length(); |
| 10608 intptr_t len2 = str2.Length(); | 10643 intptr_t len2 = str2.Length(); |
| 10609 intptr_t len = len1 + len2; | 10644 intptr_t len = len1 + len2; |
| 10610 const TwoByteString& result = | 10645 const String& result = String::Handle(TwoByteString::New(len, space)); |
| 10611 TwoByteString::Handle(TwoByteString::New(len, space)); | |
| 10612 String::Copy(result, 0, str1, 0, len1); | 10646 String::Copy(result, 0, str1, 0, len1); |
| 10613 String::Copy(result, len1, str2, 0, len2); | 10647 String::Copy(result, len1, str2, 0, len2); |
| 10614 return result.raw(); | 10648 return TwoByteString::raw(result); |
| 10615 } | 10649 } |
| 10616 | 10650 |
| 10617 | 10651 |
| 10618 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings, | 10652 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings, |
| 10619 intptr_t len, | 10653 intptr_t len, |
| 10620 Heap::Space space) { | 10654 Heap::Space space) { |
| 10621 const TwoByteString& result = | 10655 const String& result = String::Handle(TwoByteString::New(len, space)); |
| 10622 TwoByteString::Handle(TwoByteString::New(len, space)); | |
| 10623 String& str = String::Handle(); | 10656 String& str = String::Handle(); |
| 10624 intptr_t strings_len = strings.Length(); | 10657 intptr_t strings_len = strings.Length(); |
| 10625 intptr_t pos = 0; | 10658 intptr_t pos = 0; |
| 10626 for (intptr_t i = 0; i < strings_len; i++) { | 10659 for (intptr_t i = 0; i < strings_len; i++) { |
| 10627 str ^= strings.At(i); | 10660 str ^= strings.At(i); |
| 10628 intptr_t str_len = str.Length(); | 10661 intptr_t str_len = str.Length(); |
| 10629 String::Copy(result, pos, str, 0, str_len); | 10662 String::Copy(result, pos, str, 0, str_len); |
| 10630 pos += str_len; | 10663 pos += str_len; |
| 10631 } | 10664 } |
| 10632 return result.raw(); | 10665 return TwoByteString::raw(result); |
| 10633 } | 10666 } |
| 10634 | 10667 |
| 10635 | 10668 |
| 10636 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch), | 10669 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch), |
| 10637 const String& str, | 10670 const String& str, |
| 10638 Heap::Space space) { | 10671 Heap::Space space) { |
| 10639 ASSERT(!str.IsNull()); | 10672 ASSERT(!str.IsNull()); |
| 10640 intptr_t len = str.Length(); | 10673 intptr_t len = str.Length(); |
| 10641 const TwoByteString& result = | 10674 const String& result = String::Handle(TwoByteString::New(len, space)); |
| 10642 TwoByteString::Handle(TwoByteString::New(len, space)); | |
| 10643 for (intptr_t i = 0; i < len; ++i) { | 10675 for (intptr_t i = 0; i < len; ++i) { |
| 10644 int32_t ch = mapping(str.CharAt(i)); | 10676 int32_t ch = mapping(str.CharAt(i)); |
| 10645 ASSERT(ch >= 0 && ch <= 0xFFFF); | 10677 ASSERT(ch >= 0 && ch <= 0xFFFF); |
| 10646 *result.CharAddr(i) = ch; | 10678 *CharAddr(result, i) = ch; |
| 10647 } | 10679 } |
| 10648 return result.raw(); | 10680 return TwoByteString::raw(result); |
| 10649 } | 10681 } |
| 10650 | 10682 |
| 10651 | 10683 |
| 10652 const char* TwoByteString::ToCString() const { | |
| 10653 return String::ToCString(); | |
| 10654 } | |
| 10655 | |
| 10656 | |
| 10657 static void AddFinalizer(const Object& referent, | 10684 static void AddFinalizer(const Object& referent, |
| 10658 void* peer, | 10685 void* peer, |
| 10659 Dart_WeakPersistentHandleFinalizer callback) { | 10686 Dart_WeakPersistentHandleFinalizer callback) { |
| 10660 ASSERT(callback != NULL); | 10687 ASSERT(callback != NULL); |
| 10661 ApiState* state = Isolate::Current()->api_state(); | 10688 ApiState* state = Isolate::Current()->api_state(); |
| 10662 ASSERT(state != NULL); | 10689 ASSERT(state != NULL); |
| 10663 FinalizablePersistentHandle* weak_ref = | 10690 FinalizablePersistentHandle* weak_ref = |
| 10664 state->weak_persistent_handles().AllocateHandle(); | 10691 state->weak_persistent_handles().AllocateHandle(); |
| 10665 weak_ref->set_raw(referent); | 10692 weak_ref->set_raw(referent); |
| 10666 weak_ref->set_peer(peer); | 10693 weak_ref->set_peer(peer); |
| 10667 weak_ref->set_callback(callback); | 10694 weak_ref->set_callback(callback); |
| 10668 } | 10695 } |
| 10669 | 10696 |
| 10670 | 10697 |
| 10671 RawExternalOneByteString* ExternalOneByteString::New( | 10698 RawExternalOneByteString* ExternalOneByteString::New( |
| 10672 const uint8_t* data, | 10699 const uint8_t* data, |
| 10673 intptr_t len, | 10700 intptr_t len, |
| 10674 void* peer, | 10701 void* peer, |
| 10675 Dart_PeerFinalizer callback, | 10702 Dart_PeerFinalizer callback, |
| 10676 Heap::Space space) { | 10703 Heap::Space space) { |
| 10677 ASSERT(Isolate::Current()->object_store()->external_one_byte_string_class() != | 10704 ASSERT(Isolate::Current()->object_store()-> |
| 10678 Class::null()); | 10705 external_one_byte_string_class() != Class::null()); |
| 10679 if (len < 0 || len > kMaxElements) { | 10706 if (len < 0 || len > kMaxElements) { |
| 10680 // This should be caught before we reach here. | 10707 // This should be caught before we reach here. |
| 10681 FATAL1("Fatal error in ExternalOneByteString::New: invalid len %"Pd"\n", | 10708 FATAL1("Fatal error in ExternalOneByteString::New: invalid len %"Pd"\n", |
| 10682 len); | 10709 len); |
| 10683 } | 10710 } |
| 10684 ExternalOneByteString& result = ExternalOneByteString::Handle(); | 10711 String& result = String::Handle(); |
| 10685 ExternalStringData<uint8_t>* external_data = | 10712 ExternalStringData<uint8_t>* external_data = |
| 10686 new ExternalStringData<uint8_t>(data, peer, callback); | 10713 new ExternalStringData<uint8_t>(data, peer, callback); |
| 10687 { | 10714 { |
| 10688 RawObject* raw = Object::Allocate(ExternalOneByteString::kClassId, | 10715 RawObject* raw = Object::Allocate(ExternalOneByteString::kClassId, |
| 10689 ExternalOneByteString::InstanceSize(), | 10716 ExternalOneByteString::InstanceSize(), |
| 10690 space); | 10717 space); |
| 10691 NoGCScope no_gc; | 10718 NoGCScope no_gc; |
| 10692 result ^= raw; | 10719 result ^= raw; |
| 10693 result.SetLength(len); | 10720 result.SetLength(len); |
| 10694 result.SetHash(0); | 10721 result.SetHash(0); |
| 10695 result.SetExternalData(external_data); | 10722 SetExternalData(result, external_data); |
| 10696 } | 10723 } |
| 10697 AddFinalizer(result, external_data, ExternalOneByteString::Finalize); | 10724 AddFinalizer(result, external_data, ExternalOneByteString::Finalize); |
| 10698 return result.raw(); | 10725 return ExternalOneByteString::raw(result); |
| 10699 } | 10726 } |
| 10700 | 10727 |
| 10701 | 10728 |
| 10702 static void DeleteWeakPersistentHandle(Dart_Handle handle) { | 10729 static void DeleteWeakPersistentHandle(Dart_Handle handle) { |
| 10703 ApiState* state = Isolate::Current()->api_state(); | 10730 ApiState* state = Isolate::Current()->api_state(); |
| 10704 ASSERT(state != NULL); | 10731 ASSERT(state != NULL); |
| 10705 FinalizablePersistentHandle* weak_ref = | 10732 FinalizablePersistentHandle* weak_ref = |
| 10706 reinterpret_cast<FinalizablePersistentHandle*>(handle); | 10733 reinterpret_cast<FinalizablePersistentHandle*>(handle); |
| 10707 ASSERT(state->IsValidWeakPersistentHandle(handle)); | 10734 ASSERT(state->IsValidWeakPersistentHandle(handle)); |
| 10708 state->weak_persistent_handles().FreeHandle(weak_ref); | 10735 state->weak_persistent_handles().FreeHandle(weak_ref); |
| 10709 } | 10736 } |
| 10710 | 10737 |
| 10711 | 10738 |
| 10712 void ExternalOneByteString::Finalize(Dart_Handle handle, void* peer) { | 10739 void ExternalOneByteString::Finalize(Dart_Handle handle, void* peer) { |
| 10713 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); | 10740 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); |
| 10714 DeleteWeakPersistentHandle(handle); | 10741 DeleteWeakPersistentHandle(handle); |
| 10715 } | 10742 } |
| 10716 | 10743 |
| 10717 | 10744 |
| 10718 const char* ExternalOneByteString::ToCString() const { | |
| 10719 return String::ToCString(); | |
| 10720 } | |
| 10721 | |
| 10722 | |
| 10723 RawExternalTwoByteString* ExternalTwoByteString::New( | 10745 RawExternalTwoByteString* ExternalTwoByteString::New( |
| 10724 const uint16_t* data, | 10746 const uint16_t* data, |
| 10725 intptr_t len, | 10747 intptr_t len, |
| 10726 void* peer, | 10748 void* peer, |
| 10727 Dart_PeerFinalizer callback, | 10749 Dart_PeerFinalizer callback, |
| 10728 Heap::Space space) { | 10750 Heap::Space space) { |
| 10729 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != | 10751 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != |
| 10730 Class::null()); | 10752 Class::null()); |
| 10731 if (len < 0 || len > kMaxElements) { | 10753 if (len < 0 || len > kMaxElements) { |
| 10732 // This should be caught before we reach here. | 10754 // This should be caught before we reach here. |
| 10733 FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %"Pd"\n", | 10755 FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %"Pd"\n", |
| 10734 len); | 10756 len); |
| 10735 } | 10757 } |
| 10736 ExternalTwoByteString& result = ExternalTwoByteString::Handle(); | 10758 String& result = String::Handle(); |
| 10737 ExternalStringData<uint16_t>* external_data = | 10759 ExternalStringData<uint16_t>* external_data = |
| 10738 new ExternalStringData<uint16_t>(data, peer, callback); | 10760 new ExternalStringData<uint16_t>(data, peer, callback); |
| 10739 { | 10761 { |
| 10740 RawObject* raw = Object::Allocate(ExternalTwoByteString::kClassId, | 10762 RawObject* raw = Object::Allocate(ExternalTwoByteString::kClassId, |
| 10741 ExternalTwoByteString::InstanceSize(), | 10763 ExternalTwoByteString::InstanceSize(), |
| 10742 space); | 10764 space); |
| 10743 NoGCScope no_gc; | 10765 NoGCScope no_gc; |
| 10744 result ^= raw; | 10766 result ^= raw; |
| 10745 result.SetLength(len); | 10767 result.SetLength(len); |
| 10746 result.SetHash(0); | 10768 result.SetHash(0); |
| 10747 result.SetExternalData(external_data); | 10769 SetExternalData(result, external_data); |
| 10748 } | 10770 } |
| 10749 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize); | 10771 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize); |
| 10750 return result.raw(); | 10772 return ExternalTwoByteString::raw(result); |
| 10751 } | 10773 } |
| 10752 | 10774 |
| 10753 | 10775 |
| 10754 void ExternalTwoByteString::Finalize(Dart_Handle handle, void* peer) { | 10776 void ExternalTwoByteString::Finalize(Dart_Handle handle, void* peer) { |
| 10755 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | 10777 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
| 10756 DeleteWeakPersistentHandle(handle); | 10778 DeleteWeakPersistentHandle(handle); |
| 10757 } | 10779 } |
| 10758 | 10780 |
| 10759 | 10781 |
| 10760 const char* ExternalTwoByteString::ToCString() const { | |
| 10761 return String::ToCString(); | |
| 10762 } | |
| 10763 | |
| 10764 | |
| 10765 RawBool* Bool::True() { | 10782 RawBool* Bool::True() { |
| 10766 return Isolate::Current()->object_store()->true_value(); | 10783 return Isolate::Current()->object_store()->true_value(); |
| 10767 } | 10784 } |
| 10768 | 10785 |
| 10769 | 10786 |
| 10770 RawBool* Bool::False() { | 10787 RawBool* Bool::False() { |
| 10771 return Isolate::Current()->object_store()->false_value(); | 10788 return Isolate::Current()->object_store()->false_value(); |
| 10772 } | 10789 } |
| 10773 | 10790 |
| 10774 | 10791 |
| (...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11893 } | 11910 } |
| 11894 return result.raw(); | 11911 return result.raw(); |
| 11895 } | 11912 } |
| 11896 | 11913 |
| 11897 | 11914 |
| 11898 const char* WeakProperty::ToCString() const { | 11915 const char* WeakProperty::ToCString() const { |
| 11899 return "_WeakProperty"; | 11916 return "_WeakProperty"; |
| 11900 } | 11917 } |
| 11901 | 11918 |
| 11902 } // namespace dart | 11919 } // namespace dart |
| OLD | NEW |