Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: runtime/vm/object.cc

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 // Return a TypeParameter if the type_name is a type parameter of this class. 1552 // Return a TypeParameter if the type_name is a type parameter of this class.
1553 // Return null otherwise. 1553 // Return null otherwise.
1554 RawTypeParameter* Class::LookupTypeParameter(const String& type_name, 1554 RawTypeParameter* Class::LookupTypeParameter(const String& type_name,
1555 intptr_t token_pos) const { 1555 intptr_t token_pos) const {
1556 ASSERT(!type_name.IsNull()); 1556 ASSERT(!type_name.IsNull());
1557 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); 1557 const TypeArguments& type_params = TypeArguments::Handle(type_parameters());
1558 if (!type_params.IsNull()) { 1558 if (!type_params.IsNull()) {
1559 intptr_t num_type_params = type_params.Length(); 1559 intptr_t num_type_params = type_params.Length();
1560 TypeParameter& type_param = TypeParameter::Handle(); 1560 TypeParameter& type_param = TypeParameter::Handle();
1561 String& type_param_name = String::Handle(); 1561 String& type_param_name = String::Handle();
1562 AbstractType& bound = AbstractType::Handle(); 1562 // TODO(regis): We do not copy the bound (= type_param.bound()), since
1563 // we are not able to finalize the bounds of type parameter references
1564 // without getting into cycles. Revisit.
1565 const AbstractType& bound = AbstractType::Handle(
1566 Isolate::Current()->object_store()->object_type());
1563 for (intptr_t i = 0; i < num_type_params; i++) { 1567 for (intptr_t i = 0; i < num_type_params; i++) {
1564 type_param ^= type_params.TypeAt(i); 1568 type_param ^= type_params.TypeAt(i);
1565 type_param_name = type_param.name(); 1569 type_param_name = type_param.name();
1566 if (type_param_name.Equals(type_name)) { 1570 if (type_param_name.Equals(type_name)) {
1567 intptr_t index = type_param.index(); 1571 intptr_t index = type_param.index();
1568 bound = type_param.bound();
1569 // Create a non-finalized new TypeParameter with the given token_pos. 1572 // Create a non-finalized new TypeParameter with the given token_pos.
1570 if (type_param.IsFinalized()) { 1573 if (type_param.IsFinalized()) {
1571 // The index was adjusted during finalization. Revert. 1574 // The index was adjusted during finalization. Revert.
1572 index -= NumTypeArguments() - num_type_params; 1575 index -= NumTypeArguments() - num_type_params;
1573 } else { 1576 } else {
1574 ASSERT(type_param.index() == i); 1577 ASSERT(type_param.index() == i);
1575 } 1578 }
1576 return TypeParameter::New(*this, index, type_name, bound, token_pos); 1579 return TypeParameter::New(*this, index, type_name, bound, token_pos);
1577 } 1580 }
1578 } 1581 }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 cls.set_num_native_fields(field_count); 1874 cls.set_num_native_fields(field_count);
1872 cls.set_is_finalized(); 1875 cls.set_is_finalized();
1873 library.AddClass(cls); 1876 library.AddClass(cls);
1874 return cls.raw(); 1877 return cls.raw();
1875 } else { 1878 } else {
1876 return Class::null(); 1879 return Class::null();
1877 } 1880 }
1878 } 1881 }
1879 1882
1880 1883
1884 RawClass* Class::NewStringClass(intptr_t class_id) {
1885 intptr_t instance_size;
1886 if (class_id == kOneByteStringCid) {
1887 instance_size = OneByteString::InstanceSize();
1888 } else if (class_id == kTwoByteStringCid) {
1889 instance_size = TwoByteString::InstanceSize();
1890 } else if (class_id == kExternalOneByteStringCid) {
1891 instance_size = ExternalOneByteString::InstanceSize();
1892 } else {
1893 ASSERT(class_id == kExternalTwoByteStringCid);
1894 instance_size = ExternalTwoByteString::InstanceSize();
1895 }
1896 Class& result = Class::Handle(New<String>(class_id));
1897 result.set_instance_size(instance_size);
1898 result.set_next_field_offset(instance_size);
1899 result.set_is_prefinalized();
1900 return result.raw();
1901 }
1902
1903
1881 void Class::set_name(const String& value) const { 1904 void Class::set_name(const String& value) const {
1882 ASSERT(value.IsSymbol()); 1905 ASSERT(value.IsSymbol());
1883 StorePointer(&raw_ptr()->name_, value.raw()); 1906 StorePointer(&raw_ptr()->name_, value.raw());
1884 } 1907 }
1885 1908
1886 1909
1887 void Class::set_script(const Script& value) const { 1910 void Class::set_script(const Script& value) const {
1888 StorePointer(&raw_ptr()->script_, value.raw()); 1911 StorePointer(&raw_ptr()->script_, value.raw());
1889 } 1912 }
1890 1913
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
2184 return false; 2207 return false;
2185 } 2208 }
2186 } 2209 }
2187 return true; 2210 return true;
2188 } 2211 }
2189 2212
2190 2213
2191 RawFunction* Class::LookupFunction(const String& name) const { 2214 RawFunction* Class::LookupFunction(const String& name) const {
2192 Isolate* isolate = Isolate::Current(); 2215 Isolate* isolate = Isolate::Current();
2193 ASSERT(name.IsOneByteString()); 2216 ASSERT(name.IsOneByteString());
2194 const OneByteString& lookup_name = OneByteString::Cast(name);
2195 Array& funcs = Array::Handle(isolate, functions()); 2217 Array& funcs = Array::Handle(isolate, functions());
2196 if (funcs.IsNull()) { 2218 if (funcs.IsNull()) {
2197 // This can occur, e.g., for Null classes. 2219 // This can occur, e.g., for Null classes.
2198 return Function::null(); 2220 return Function::null();
2199 } 2221 }
2200 Function& function = Function::Handle(isolate, Function::null()); 2222 Function& function = Function::Handle(isolate, Function::null());
2201 OneByteString& function_name = 2223 String& function_name = String::Handle(isolate, String::null());
2202 OneByteString::Handle(isolate, OneByteString::null());
2203 intptr_t len = funcs.Length(); 2224 intptr_t len = funcs.Length();
2204 for (intptr_t i = 0; i < len; i++) { 2225 for (intptr_t i = 0; i < len; i++) {
2205 function ^= funcs.At(i); 2226 function ^= funcs.At(i);
2206 function_name ^= function.name(); 2227 function_name ^= function.name();
2207 if (function_name.EqualsIgnoringPrivateKey(lookup_name)) { 2228 if (OneByteString::EqualsIgnoringPrivateKey(function_name, name)) {
2208 return function.raw(); 2229 return function.raw();
2209 } 2230 }
2210 } 2231 }
2211 2232
2212 // No function found. 2233 // No function found.
2213 return Function::null(); 2234 return Function::null();
2214 } 2235 }
2215 2236
2216 2237
2217 RawFunction* Class::LookupGetterFunction(const String& name) const { 2238 RawFunction* Class::LookupGetterFunction(const String& name) const {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 return field.raw(); 2314 return field.raw();
2294 } 2315 }
2295 // No field found. 2316 // No field found.
2296 return Field::null(); 2317 return Field::null();
2297 } 2318 }
2298 2319
2299 2320
2300 RawField* Class::LookupField(const String& name) const { 2321 RawField* Class::LookupField(const String& name) const {
2301 Isolate* isolate = Isolate::Current(); 2322 Isolate* isolate = Isolate::Current();
2302 ASSERT(name.IsOneByteString()); 2323 ASSERT(name.IsOneByteString());
2303 const OneByteString& lookup_name = OneByteString::Cast(name);
2304 const Array& flds = Array::Handle(isolate, fields()); 2324 const Array& flds = Array::Handle(isolate, fields());
2305 Field& field = Field::Handle(isolate, Field::null()); 2325 Field& field = Field::Handle(isolate, Field::null());
2306 OneByteString& field_name = 2326 String& field_name = String::Handle(isolate, String::null());
2307 OneByteString::Handle(isolate, OneByteString::null());
2308 intptr_t len = flds.Length(); 2327 intptr_t len = flds.Length();
2309 for (intptr_t i = 0; i < len; i++) { 2328 for (intptr_t i = 0; i < len; i++) {
2310 field ^= flds.At(i); 2329 field ^= flds.At(i);
2311 field_name ^= field.name(); 2330 field_name ^= field.name();
2312 if (field_name.EqualsIgnoringPrivateKey(lookup_name)) { 2331 if (OneByteString::EqualsIgnoringPrivateKey(field_name, name)) {
2313 return field.raw(); 2332 return field.raw();
2314 } 2333 }
2315 } 2334 }
2316 // No field found. 2335 // No field found.
2317 return Field::null(); 2336 return Field::null();
2318 } 2337 }
2319 2338
2320 2339
2321 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { 2340 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const {
2322 Isolate* isolate = Isolate::Current(); 2341 Isolate* isolate = Isolate::Current();
(...skipping 4860 matching lines...) Expand 10 before | Expand all | Expand 10 after
7183 const Array& result = Array::Handle(Array::New(max_id + 1)); 7202 const Array& result = Array::Handle(Array::New(max_id + 1));
7184 for (intptr_t i = 0; i < deopt_ids.length(); i++) { 7203 for (intptr_t i = 0; i < deopt_ids.length(); i++) {
7185 intptr_t result_index = deopt_ids[i]; 7204 intptr_t result_index = deopt_ids[i];
7186 ASSERT(result.At(result_index) == Object::null()); 7205 ASSERT(result.At(result_index) == Object::null());
7187 result.SetAt(result_index, Object::Handle(ic_data_objs.At(i))); 7206 result.SetAt(result_index, Object::Handle(ic_data_objs.At(i)));
7188 } 7207 }
7189 return result.raw(); 7208 return result.raw();
7190 } 7209 }
7191 7210
7192 7211
7212 void Code::ExtractUncalledStaticCallDeoptIds(
7213 GrowableArray<intptr_t>* deopt_ids) const {
7214 ASSERT(deopt_ids != NULL);
7215 deopt_ids->Clear();
7216 const PcDescriptors& descriptors =
7217 PcDescriptors::Handle(this->pc_descriptors());
7218 Function& function = Function::Handle();
7219 for (intptr_t i = 0; i < descriptors.Length(); i++) {
7220 if (descriptors.DescriptorKind(i) == PcDescriptors::kFuncCall) {
7221 // Static call.
7222 uword target_addr;
7223 CodePatcher::GetStaticCallAt(descriptors.PC(i), &function, &target_addr);
7224 if (target_addr == StubCode::CallStaticFunctionEntryPoint()) {
7225 deopt_ids->Add(descriptors.DeoptId(i));
7226 }
7227 }
7228 }
7229 }
7230
7231
7193 RawStackmap* Code::GetStackmap(uword pc, Array* maps, Stackmap* map) const { 7232 RawStackmap* Code::GetStackmap(uword pc, Array* maps, Stackmap* map) const {
7194 // This code is used during iterating frames during a GC and hence it 7233 // This code is used during iterating frames during a GC and hence it
7195 // should not in turn start a GC. 7234 // should not in turn start a GC.
7196 NoGCScope no_gc; 7235 NoGCScope no_gc;
7197 if (stackmaps() == Array::null()) { 7236 if (stackmaps() == Array::null()) {
7198 // No stack maps are present in the code object which means this 7237 // No stack maps are present in the code object which means this
7199 // frame relies on tagged pointers. 7238 // frame relies on tagged pointers.
7200 return Stackmap::null(); 7239 return Stackmap::null();
7201 } 7240 }
7202 // A stack map is present in the code object, use the stack map to visit 7241 // A stack map is present in the code object, use the stack map to visit
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after
9005 // Integer is an interface. No instances of Integer should exist. 9044 // Integer is an interface. No instances of Integer should exist.
9006 UNREACHABLE(); 9045 UNREACHABLE();
9007 return "Integer"; 9046 return "Integer";
9008 } 9047 }
9009 9048
9010 9049
9011 RawInteger* Integer::New(const String& str, Heap::Space space) { 9050 RawInteger* Integer::New(const String& str, Heap::Space space) {
9012 // We are not supposed to have integers represented as two byte or 9051 // We are not supposed to have integers represented as two byte or
9013 // four byte strings. 9052 // four byte strings.
9014 ASSERT(str.IsOneByteString()); 9053 ASSERT(str.IsOneByteString());
9015 const OneByteString& onestr = OneByteString::Cast(str);
9016 int64_t value; 9054 int64_t value;
9017 if (!OS::StringToInt64(onestr.ToCString(), &value)) { 9055 if (!OS::StringToInt64(str.ToCString(), &value)) {
9018 const Bigint& big = Bigint::Handle(Bigint::New(onestr, space)); 9056 const Bigint& big = Bigint::Handle(Bigint::New(str, space));
9019 ASSERT(!BigintOperations::FitsIntoSmi(big)); 9057 ASSERT(!BigintOperations::FitsIntoSmi(big));
9020 ASSERT(!BigintOperations::FitsIntoMint(big)); 9058 ASSERT(!BigintOperations::FitsIntoMint(big));
9021 return big.raw(); 9059 return big.raw();
9022 } 9060 }
9023 return Integer::New(value, space); 9061 return Integer::New(value, space);
9024 } 9062 }
9025 9063
9026 9064
9027 RawInteger* Integer::New(int64_t value, Heap::Space space) { 9065 RawInteger* Integer::New(int64_t value, Heap::Space space) {
9028 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) { 9066 if ((value <= Smi::kMaxValue) && (value >= Smi::kMinValue)) {
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
9773 return HashImpl(characters, len); 9811 return HashImpl(characters, len);
9774 } 9812 }
9775 9813
9776 9814
9777 intptr_t String::Hash(const uint32_t* characters, intptr_t len) { 9815 intptr_t String::Hash(const uint32_t* characters, intptr_t len) {
9778 return HashImpl(characters, len); 9816 return HashImpl(characters, len);
9779 } 9817 }
9780 9818
9781 9819
9782 int32_t String::CharAt(intptr_t index) const { 9820 int32_t String::CharAt(intptr_t index) const {
9783 // String is an abstract class. 9821 intptr_t class_id = raw()->GetClassId();
9784 UNREACHABLE(); 9822 ASSERT(RawObject::IsStringClassId(class_id));
9785 return 0; 9823 NoGCScope no_gc;
9824 if (class_id == kOneByteStringCid) {
9825 return *OneByteString::CharAddr(*this, index);
9826 }
9827 if (class_id == kTwoByteStringCid) {
9828 return *TwoByteString::CharAddr(*this, index);
9829 }
9830 if (class_id == kExternalOneByteStringCid) {
9831 return *ExternalOneByteString::CharAddr(*this, index);
9832 }
9833 ASSERT(class_id == kExternalTwoByteStringCid);
9834 return *ExternalTwoByteString::CharAddr(*this, index);
9786 } 9835 }
9787 9836
9788 9837
9789 intptr_t String::CharSize() const { 9838 intptr_t String::CharSize() const {
9790 // String is an abstract class. 9839 intptr_t class_id = raw()->GetClassId();
9791 UNREACHABLE(); 9840 if (class_id == kOneByteStringCid || class_id == kExternalOneByteStringCid) {
9792 return 0; 9841 return kOneByteChar;
9842 }
9843 ASSERT(class_id == kTwoByteStringCid ||
9844 class_id == kExternalTwoByteStringCid);
9845 return kTwoByteChar;
9793 } 9846 }
9794 9847
9795 9848
9849 void* String::GetPeer() const {
9850 intptr_t class_id = raw()->GetClassId();
9851 if (class_id == kExternalOneByteStringCid) {
9852 return ExternalOneByteString::GetPeer(*this);
9853 }
9854 ASSERT(class_id == kExternalTwoByteStringCid);
9855 return ExternalTwoByteString::GetPeer(*this);
9856 }
9857
9858
9796 bool String::Equals(const Instance& other) const { 9859 bool String::Equals(const Instance& other) const {
9797 if (this->raw() == other.raw()) { 9860 if (this->raw() == other.raw()) {
9798 // Both handles point to the same raw instance. 9861 // Both handles point to the same raw instance.
9799 return true; 9862 return true;
9800 } 9863 }
9801 9864
9802 if (!other.IsString() || other.IsNull()) { 9865 if (!other.IsString() || other.IsNull()) {
9803 return false; 9866 return false;
9804 } 9867 }
9805 9868
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
9928 return String::New(utf8_array, array_len, space); 9991 return String::New(utf8_array, array_len, space);
9929 } 9992 }
9930 9993
9931 9994
9932 RawString* String::New(const uint8_t* utf8_array, 9995 RawString* String::New(const uint8_t* utf8_array,
9933 intptr_t array_len, 9996 intptr_t array_len,
9934 Heap::Space space) { 9997 Heap::Space space) {
9935 Utf8::Type type; 9998 Utf8::Type type;
9936 intptr_t len = Utf8::CodePointCount(utf8_array, array_len, &type); 9999 intptr_t len = Utf8::CodePointCount(utf8_array, array_len, &type);
9937 if (type == Utf8::kAscii) { 10000 if (type == Utf8::kAscii) {
9938 const OneByteString& strobj 10001 const String& strobj = String::Handle(OneByteString::New(len, space));
9939 = OneByteString::Handle(OneByteString::New(len, space));
9940 if (len > 0) { 10002 if (len > 0) {
9941 NoGCScope no_gc; 10003 NoGCScope no_gc;
9942 Utf8::DecodeToAscii(utf8_array, array_len, strobj.CharAddr(0), len); 10004 Utf8::DecodeToAscii(utf8_array, array_len,
10005 OneByteString::CharAddr(strobj, 0), len);
9943 } 10006 }
9944 return strobj.raw(); 10007 return strobj.raw();
9945 } 10008 }
9946 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP)); 10009 ASSERT((type == Utf8::kBMP) || (type == Utf8::kSMP));
9947 const TwoByteString& strobj = 10010 const String& strobj = String::Handle(TwoByteString::New(len, space));
9948 TwoByteString::Handle(TwoByteString::New(len, space));
9949 NoGCScope no_gc; 10011 NoGCScope no_gc;
9950 Utf8::DecodeToUTF16(utf8_array, array_len, strobj.CharAddr(0), len); 10012 Utf8::DecodeToUTF16(utf8_array, array_len,
10013 TwoByteString::CharAddr(strobj, 0), len);
9951 return strobj.raw(); 10014 return strobj.raw();
9952 } 10015 }
9953 10016
9954 10017
9955 RawString* String::New(const uint16_t* utf16_array, 10018 RawString* String::New(const uint16_t* utf16_array,
9956 intptr_t array_len, 10019 intptr_t array_len,
9957 Heap::Space space) { 10020 Heap::Space space) {
9958 bool is_one_byte_string = true; 10021 bool is_one_byte_string = true;
9959 for (intptr_t i = 0; i < array_len; ++i) { 10022 for (intptr_t i = 0; i < array_len; ++i) {
9960 if (utf16_array[i] > 0x7F) { 10023 if (utf16_array[i] > 0x7F) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
10026 } 10089 }
10027 10090
10028 10091
10029 void String::Copy(const String& dst, intptr_t dst_offset, 10092 void String::Copy(const String& dst, intptr_t dst_offset,
10030 const uint8_t* characters, 10093 const uint8_t* characters,
10031 intptr_t len) { 10094 intptr_t len) {
10032 ASSERT(dst_offset >= 0); 10095 ASSERT(dst_offset >= 0);
10033 ASSERT(len >= 0); 10096 ASSERT(len >= 0);
10034 ASSERT(len <= (dst.Length() - dst_offset)); 10097 ASSERT(len <= (dst.Length() - dst_offset));
10035 if (dst.IsOneByteString()) { 10098 if (dst.IsOneByteString()) {
10036 const OneByteString& onestr = OneByteString::Cast(dst);
10037 NoGCScope no_gc; 10099 NoGCScope no_gc;
10038 if (len > 0) { 10100 if (len > 0) {
10039 memmove(onestr.CharAddr(dst_offset), characters, len); 10101 memmove(OneByteString::CharAddr(dst, dst_offset),
10102 characters,
10103 len);
10040 } 10104 }
10041 } else if (dst.IsTwoByteString()) { 10105 } else if (dst.IsTwoByteString()) {
10042 const TwoByteString& twostr = TwoByteString::Cast(dst);
10043 NoGCScope no_gc;
10044 for (intptr_t i = 0; i < len; ++i) { 10106 for (intptr_t i = 0; i < len; ++i) {
10045 *twostr.CharAddr(i + dst_offset) = characters[i]; 10107 *TwoByteString::CharAddr(dst, i + dst_offset) = characters[i];
10046 } 10108 }
10047 } 10109 }
10048 } 10110 }
10049 10111
10050 10112
10051 void String::Copy(const String& dst, intptr_t dst_offset, 10113 void String::Copy(const String& dst, intptr_t dst_offset,
10052 const uint16_t* utf16_array, 10114 const uint16_t* utf16_array,
10053 intptr_t array_len) { 10115 intptr_t array_len) {
10054 ASSERT(dst_offset >= 0); 10116 ASSERT(dst_offset >= 0);
10055 ASSERT(array_len >= 0); 10117 ASSERT(array_len >= 0);
10056 ASSERT(array_len <= (dst.Length() - dst_offset)); 10118 ASSERT(array_len <= (dst.Length() - dst_offset));
10057 if (dst.IsOneByteString()) { 10119 if (dst.IsOneByteString()) {
10058 const OneByteString& onestr = OneByteString::Cast(dst);
10059 NoGCScope no_gc; 10120 NoGCScope no_gc;
10060 for (intptr_t i = 0; i < array_len; ++i) { 10121 for (intptr_t i = 0; i < array_len; ++i) {
10061 ASSERT(utf16_array[i] <= 0x7F); 10122 ASSERT(utf16_array[i] <= 0x7F);
10062 *onestr.CharAddr(i + dst_offset) = utf16_array[i]; 10123 *OneByteString::CharAddr(dst, i + dst_offset) = utf16_array[i];
10063 } 10124 }
10064 } else { 10125 } else {
10065 ASSERT(dst.IsTwoByteString()); 10126 ASSERT(dst.IsTwoByteString());
10066 const TwoByteString& twostr = TwoByteString::Cast(dst);
10067 NoGCScope no_gc; 10127 NoGCScope no_gc;
10068 if (array_len > 0) { 10128 if (array_len > 0) {
10069 memmove(twostr.CharAddr(dst_offset), utf16_array, (array_len * 2)); 10129 memmove(TwoByteString::CharAddr(dst, dst_offset),
10130 utf16_array,
10131 array_len * 2);
10070 } 10132 }
10071 } 10133 }
10072 } 10134 }
10073 10135
10074 10136
10075 void String::Copy(const String& dst, intptr_t dst_offset, 10137 void String::Copy(const String& dst, intptr_t dst_offset,
10076 const String& src, intptr_t src_offset, 10138 const String& src, intptr_t src_offset,
10077 intptr_t len) { 10139 intptr_t len) {
10078 ASSERT(dst_offset >= 0); 10140 ASSERT(dst_offset >= 0);
10079 ASSERT(src_offset >= 0); 10141 ASSERT(src_offset >= 0);
10080 ASSERT(len >= 0); 10142 ASSERT(len >= 0);
10081 ASSERT(len <= (dst.Length() - dst_offset)); 10143 ASSERT(len <= (dst.Length() - dst_offset));
10082 ASSERT(len <= (src.Length() - src_offset)); 10144 ASSERT(len <= (src.Length() - src_offset));
10083 if (len > 0) { 10145 if (len > 0) {
10084 intptr_t char_size = src.CharSize(); 10146 intptr_t char_size = src.CharSize();
10085 if (char_size == kOneByteChar) { 10147 if (char_size == kOneByteChar) {
10086 if (src.IsOneByteString()) { 10148 if (src.IsOneByteString()) {
10087 const OneByteString& onestr = OneByteString::Cast(src);
10088 NoGCScope no_gc; 10149 NoGCScope no_gc;
10089 String::Copy(dst, dst_offset, onestr.CharAddr(0) + src_offset, len); 10150 String::Copy(dst,
10151 dst_offset,
10152 OneByteString::CharAddr(src, src_offset),
10153 len);
10090 } else { 10154 } else {
10091 ASSERT(src.IsExternalOneByteString()); 10155 ASSERT(src.IsExternalOneByteString());
10092 const ExternalOneByteString& onestr = ExternalOneByteString::Cast(src);
10093 NoGCScope no_gc; 10156 NoGCScope no_gc;
10094 String::Copy(dst, dst_offset, onestr.CharAddr(0) + src_offset, len); 10157 String::Copy(dst,
10158 dst_offset,
10159 ExternalOneByteString::CharAddr(src, src_offset),
10160 len);
10095 } 10161 }
10096 } else { 10162 } else {
10097 ASSERT(char_size == kTwoByteChar); 10163 ASSERT(char_size == kTwoByteChar);
10098 if (src.IsTwoByteString()) { 10164 if (src.IsTwoByteString()) {
10099 const TwoByteString& twostr = TwoByteString::Cast(src);
10100 NoGCScope no_gc; 10165 NoGCScope no_gc;
10101 String::Copy(dst, dst_offset, twostr.CharAddr(0) + src_offset, len); 10166 String::Copy(dst,
10167 dst_offset,
10168 TwoByteString::CharAddr(src, src_offset),
10169 len);
10102 } else { 10170 } else {
10103 ASSERT(src.IsExternalTwoByteString()); 10171 ASSERT(src.IsExternalTwoByteString());
10104 const ExternalTwoByteString& twostr = ExternalTwoByteString::Cast(src);
10105 NoGCScope no_gc; 10172 NoGCScope no_gc;
10106 String::Copy(dst, dst_offset, twostr.CharAddr(0) + src_offset, len); 10173 String::Copy(dst,
10174 dst_offset,
10175 ExternalTwoByteString::CharAddr(src, src_offset),
10176 len);
10107 } 10177 }
10108 } 10178 }
10109 } 10179 }
10110 } 10180 }
10111 10181
10112 10182
10113 RawString* String::EscapeSpecialCharacters(const String& str, bool raw_str) { 10183 RawString* String::EscapeSpecialCharacters(const String& str, bool raw_str) {
10114 if (str.IsOneByteString()) { 10184 if (str.IsOneByteString()) {
10115 const OneByteString& onestr = OneByteString::Cast(str); 10185 return OneByteString::EscapeSpecialCharacters(str, raw_str);
10116 return onestr.EscapeSpecialCharacters(raw_str);
10117 } 10186 }
10118 ASSERT(str.IsTwoByteString()); 10187 ASSERT(str.IsTwoByteString());
10119 const TwoByteString& twostr = TwoByteString::Cast(str); 10188 return TwoByteString::EscapeSpecialCharacters(str, raw_str);
10120 return twostr.EscapeSpecialCharacters(raw_str);
10121 } 10189 }
10122 10190
10123 10191
10124 RawString* String::NewFormatted(const char* format, ...) { 10192 RawString* String::NewFormatted(const char* format, ...) {
10125 va_list args; 10193 va_list args;
10126 va_start(args, format); 10194 va_start(args, format);
10127 RawString* result = NewFormattedV(format, args); 10195 RawString* result = NewFormattedV(format, args);
10128 NoGCScope no_gc; 10196 NoGCScope no_gc;
10129 va_end(args); 10197 va_end(args);
10130 return result; 10198 return result;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
10227 Zone* zone = Isolate::Current()->current_zone(); 10295 Zone* zone = Isolate::Current()->current_zone();
10228 uint8_t* result = zone->Alloc<uint8_t>(len + 1); 10296 uint8_t* result = zone->Alloc<uint8_t>(len + 1);
10229 ToUTF8(result, len); 10297 ToUTF8(result, len);
10230 result[len] = 0; 10298 result[len] = 0;
10231 return reinterpret_cast<const char*>(result); 10299 return reinterpret_cast<const char*>(result);
10232 } 10300 }
10233 10301
10234 10302
10235 void String::ToUTF8(uint8_t* utf8_array, intptr_t array_len) const { 10303 void String::ToUTF8(uint8_t* utf8_array, intptr_t array_len) const {
10236 if (CharSize() == kOneByteChar) { 10304 if (CharSize() == kOneByteChar) {
10237 const OneByteString& obj = OneByteString::Cast(*this); 10305 const String& obj = *this;
10238 ASSERT(array_len >= obj.Length()); 10306 ASSERT(array_len >= obj.Length());
10239 if (obj.Length() > 0) { 10307 if (obj.Length() > 0) {
10240 memmove(utf8_array, obj.CharAddr(0), obj.Length()); 10308 memmove(utf8_array, OneByteString::CharAddr(obj, 0), obj.Length());
10241 } 10309 }
10242 } else { 10310 } else {
10243 ASSERT(array_len >= Utf8::Length(*this)); 10311 ASSERT(array_len >= Utf8::Length(*this));
10244 Utf8::Encode(*this, reinterpret_cast<char*>(utf8_array), array_len); 10312 Utf8::Encode(*this, reinterpret_cast<char*>(utf8_array), array_len);
10245 } 10313 }
10246 } 10314 }
10247 10315
10248 10316
10249 RawString* String::Transform(int32_t (*mapping)(int32_t ch), 10317 RawString* String::Transform(int32_t (*mapping)(int32_t ch),
10250 const String& str, 10318 const String& str,
(...skipping 27 matching lines...) Expand all
10278 return Transform(CaseMapping::ToUpper, str, space); 10346 return Transform(CaseMapping::ToUpper, str, space);
10279 } 10347 }
10280 10348
10281 10349
10282 RawString* String::ToLowerCase(const String& str, Heap::Space space) { 10350 RawString* String::ToLowerCase(const String& str, Heap::Space space) {
10283 // TODO(cshapiro): create a fast-path for OneByteString instances. 10351 // TODO(cshapiro): create a fast-path for OneByteString instances.
10284 return Transform(CaseMapping::ToLower, str, space); 10352 return Transform(CaseMapping::ToLower, str, space);
10285 } 10353 }
10286 10354
10287 10355
10288 RawOneByteString* OneByteString::EscapeSpecialCharacters(bool raw_str) const { 10356 RawOneByteString* OneByteString::EscapeSpecialCharacters(const String& str,
10289 intptr_t len = Length(); 10357 bool raw_str) {
10358 intptr_t len = str.Length();
10290 if (len > 0) { 10359 if (len > 0) {
10291 intptr_t num_escapes = 0; 10360 intptr_t num_escapes = 0;
10292 intptr_t index = 0; 10361 intptr_t index = 0;
10293 for (intptr_t i = 0; i < len; i++) { 10362 for (intptr_t i = 0; i < len; i++) {
10294 if (IsSpecialCharacter(*CharAddr(i)) || 10363 if (IsSpecialCharacter(*CharAddr(str, i)) ||
10295 (!raw_str && (*CharAddr(i) == '\\'))) { 10364 (!raw_str && (*CharAddr(str, i) == '\\'))) {
10296 num_escapes += 1; 10365 num_escapes += 1;
10297 } 10366 }
10298 } 10367 }
10299 const OneByteString& dststr = OneByteString::Handle( 10368 const String& dststr = String::Handle(
10300 OneByteString::New(len + num_escapes, Heap::kNew)); 10369 OneByteString::New(len + num_escapes, Heap::kNew));
10301 for (intptr_t i = 0; i < len; i++) { 10370 for (intptr_t i = 0; i < len; i++) {
10302 if (IsSpecialCharacter(*CharAddr(i))) { 10371 if (IsSpecialCharacter(*CharAddr(str, i))) {
10303 *(dststr.CharAddr(index)) = '\\'; 10372 *(CharAddr(dststr, index)) = '\\';
10304 *(dststr.CharAddr(index + 1)) = SpecialCharacter(*CharAddr(i)); 10373 *(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i));
10305 index += 2; 10374 index += 2;
10306 } else if (!raw_str && (*CharAddr(i) == '\\')) { 10375 } else if (!raw_str && (*CharAddr(str, i) == '\\')) {
10307 *(dststr.CharAddr(index)) = '\\'; 10376 *(CharAddr(dststr, index)) = '\\';
10308 *(dststr.CharAddr(index + 1)) = '\\'; 10377 *(CharAddr(dststr, index + 1)) = '\\';
10309 index += 2; 10378 index += 2;
10310 } else { 10379 } else {
10311 *(dststr.CharAddr(index)) = *CharAddr(i); 10380 *(CharAddr(dststr, index)) = *CharAddr(str, i);
10312 index += 1; 10381 index += 1;
10313 } 10382 }
10314 } 10383 }
10315 return dststr.raw(); 10384 return OneByteString::raw(dststr);
10316 } 10385 }
10317 return OneByteString::null(); 10386 return OneByteString::null();
10318 } 10387 }
10319 10388
10320 10389
10321 // Check to see if 'name' matches 'this' as is or 10390 // Check to see if 'str1' matches 'str2' as is or
10322 // once the private key separator is stripped from name. 10391 // once the private key separator is stripped from str2.
10323 // 10392 //
10324 // Things are made more complicated by the fact that constructors are 10393 // Things are made more complicated by the fact that constructors are
10325 // added *after* the private suffix, so "foo@123.named" should match 10394 // added *after* the private suffix, so "foo@123.named" should match
10326 // "foo.named". 10395 // "foo.named".
10327 // 10396 //
10328 // Also, the private suffix can occur more than once in the name, as in: 10397 // Also, the private suffix can occur more than once in the name, as in:
10329 // 10398 //
10330 // _ReceivePortImpl@6be832b._internal@6be832b 10399 // _ReceivePortImpl@6be832b._internal@6be832b
10331 // 10400 //
10332 bool OneByteString::EqualsIgnoringPrivateKey(const OneByteString& name) const { 10401 bool OneByteString::EqualsIgnoringPrivateKey(const String& str1,
10333 if (raw() == name.raw()) { 10402 const String& str2) {
10403 ASSERT(str2.IsOneByteString());
10404 if (str1.raw() == str2.raw()) {
10334 return true; // Both handles point to the same raw instance. 10405 return true; // Both handles point to the same raw instance.
10335 } 10406 }
10336 intptr_t len = Length(); 10407 NoGCScope no_gc;
10337 intptr_t name_len = name.Length(); 10408 intptr_t len = str1.Length();
10338 if (len == name_len) { 10409 intptr_t str2_len = str2.Length();
10410 if (len == str2_len) {
10339 for (intptr_t i = 0; i < len; i++) { 10411 for (intptr_t i = 0; i < len; i++) {
10340 if (*(CharAddr(i)) != *(name.CharAddr(i))) { 10412 if (*CharAddr(str1, i) != *CharAddr(str2, i)) {
10341 return false; 10413 return false;
10342 } 10414 }
10343 } 10415 }
10344 return true; 10416 return true;
10345 } 10417 }
10346 if (len < name_len) { 10418 if (len < str2_len) {
10347 return false; // No way they can match. 10419 return false; // No way they can match.
10348 } 10420 }
10349 intptr_t pos = 0; 10421 intptr_t pos = 0;
10350 intptr_t name_pos = 0; 10422 intptr_t str2_pos = 0;
10351 while (pos < len) { 10423 while (pos < len) {
10352 int32_t ch = *(CharAddr(pos)); 10424 int32_t ch = *CharAddr(str1, pos);
10353 pos++; 10425 pos++;
10354 10426
10355 if (ch == Scanner::kPrivateKeySeparator) { 10427 if (ch == Scanner::kPrivateKeySeparator) {
10356 // Consume a private key separator. 10428 // Consume a private key separator.
10357 while (pos < len && *(CharAddr(pos)) != '.') { 10429 while ((pos < len) && (*CharAddr(str1, pos) != '.')) {
10358 pos++; 10430 pos++;
10359 } 10431 }
10360 // Resume matching characters. 10432 // Resume matching characters.
10361 continue; 10433 continue;
10362 } 10434 }
10363 if (name_pos == name_len || ch != *(name.CharAddr(name_pos))) { 10435 if ((str2_pos == str2_len) || (ch != *CharAddr(str2, str2_pos))) {
10364 return false; 10436 return false;
10365 } 10437 }
10366 name_pos++; 10438 str2_pos++;
10367 } 10439 }
10368 10440
10369 // We have reached the end of mangled_name string. 10441 // We have reached the end of mangled_name string.
10370 ASSERT(pos == len); 10442 ASSERT(pos == len);
10371 return (name_pos == name_len); 10443 return (str2_pos == str2_len);
10372 } 10444 }
10373 10445
10374 10446
10375 RawOneByteString* OneByteString::New(intptr_t len, 10447 RawOneByteString* OneByteString::New(intptr_t len,
10376 Heap::Space space) { 10448 Heap::Space space) {
10377 ASSERT(Isolate::Current() == Dart::vm_isolate() || 10449 ASSERT(Isolate::Current() == Dart::vm_isolate() ||
10378 Isolate::Current()->object_store()->one_byte_string_class() != 10450 Isolate::Current()->object_store()->one_byte_string_class() !=
10379 Class::null()); 10451 Class::null());
10380 if (len < 0 || len > kMaxElements) { 10452 if (len < 0 || len > kMaxElements) {
10381 // This should be caught before we reach here. 10453 // This should be caught before we reach here.
10382 FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len); 10454 FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len);
10383 } 10455 }
10384 OneByteString& result = OneByteString::Handle(); 10456 String& result = String::Handle();
10385 { 10457 {
10386 RawObject* raw = Object::Allocate(OneByteString::kClassId, 10458 RawObject* raw = Object::Allocate(OneByteString::kClassId,
10387 OneByteString::InstanceSize(len), 10459 OneByteString::InstanceSize(len),
10388 space); 10460 space);
10389 NoGCScope no_gc; 10461 NoGCScope no_gc;
10390 result ^= raw; 10462 result ^= raw;
10391 result.SetLength(len); 10463 result.SetLength(len);
10392 result.SetHash(0); 10464 result.SetHash(0);
10393 } 10465 }
10394 return result.raw(); 10466 return OneByteString::raw(result);
10395 } 10467 }
10396 10468
10397 10469
10398 RawOneByteString* OneByteString::New(const uint8_t* characters, 10470 RawOneByteString* OneByteString::New(const uint8_t* characters,
10399 intptr_t len, 10471 intptr_t len,
10400 Heap::Space space) { 10472 Heap::Space space) {
10401 const OneByteString& result = 10473 const String& result = String::Handle(OneByteString::New(len, space));
10402 OneByteString::Handle(OneByteString::New(len, space));
10403 if (len > 0) { 10474 if (len > 0) {
10404 NoGCScope no_gc; 10475 NoGCScope no_gc;
10405 memmove(result.CharAddr(0), characters, len); 10476 memmove(CharAddr(result, 0), characters, len);
10406 } 10477 }
10407 return result.raw(); 10478 return OneByteString::raw(result);
10408 } 10479 }
10409 10480
10410 10481
10411 RawOneByteString* OneByteString::New(const uint16_t* characters, 10482 RawOneByteString* OneByteString::New(const uint16_t* characters,
10412 intptr_t len, 10483 intptr_t len,
10413 Heap::Space space) { 10484 Heap::Space space) {
10414 const OneByteString& result = 10485 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) { 10486 for (intptr_t i = 0; i < len; ++i) {
10417 ASSERT(characters[i] <= 0x7F); 10487 ASSERT(characters[i] <= 0x7F);
10418 *result.CharAddr(i) = characters[i]; 10488 *CharAddr(result, i) = characters[i];
10419 } 10489 }
10420 return result.raw(); 10490 return OneByteString::raw(result);
10421 } 10491 }
10422 10492
10423 10493
10424 RawOneByteString* OneByteString::New(const uint32_t* characters, 10494 RawOneByteString* OneByteString::New(const uint32_t* characters,
10425 intptr_t len, 10495 intptr_t len,
10426 Heap::Space space) { 10496 Heap::Space space) {
10427 const OneByteString& result = 10497 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) { 10498 for (intptr_t i = 0; i < len; ++i) {
10430 ASSERT(characters[i] <= 0x7F); 10499 ASSERT(characters[i] <= 0x7F);
10431 *result.CharAddr(i) = characters[i]; 10500 *CharAddr(result, i) = characters[i];
10432 } 10501 }
10433 return result.raw(); 10502 return OneByteString::raw(result);
10434 } 10503 }
10435 10504
10436 10505
10437 RawOneByteString* OneByteString::New(const OneByteString& str, 10506 RawOneByteString* OneByteString::New(const String& str,
10438 Heap::Space space) { 10507 Heap::Space space) {
10439 intptr_t len = str.Length(); 10508 intptr_t len = str.Length();
10440 const OneByteString& result = 10509 const String& result = String::Handle(OneByteString::New(len, space));
10441 OneByteString::Handle(OneByteString::New(len, space));
10442 String::Copy(result, 0, str, 0, len); 10510 String::Copy(result, 0, str, 0, len);
10443 return result.raw(); 10511 return OneByteString::raw(result);
10444 } 10512 }
10445 10513
10446 10514
10447 RawOneByteString* OneByteString::Concat(const String& str1, 10515 RawOneByteString* OneByteString::Concat(const String& str1,
10448 const String& str2, 10516 const String& str2,
10449 Heap::Space space) { 10517 Heap::Space space) {
10450 intptr_t len1 = str1.Length(); 10518 intptr_t len1 = str1.Length();
10451 intptr_t len2 = str2.Length(); 10519 intptr_t len2 = str2.Length();
10452 intptr_t len = len1 + len2; 10520 intptr_t len = len1 + len2;
10453 const OneByteString& result = 10521 const String& result = String::Handle(OneByteString::New(len, space));
10454 OneByteString::Handle(OneByteString::New(len, space));
10455 String::Copy(result, 0, str1, 0, len1); 10522 String::Copy(result, 0, str1, 0, len1);
10456 String::Copy(result, len1, str2, 0, len2); 10523 String::Copy(result, len1, str2, 0, len2);
10457 return result.raw(); 10524 return OneByteString::raw(result);
10458 } 10525 }
10459 10526
10460 10527
10461 RawOneByteString* OneByteString::ConcatAll(const Array& strings, 10528 RawOneByteString* OneByteString::ConcatAll(const Array& strings,
10462 intptr_t len, 10529 intptr_t len,
10463 Heap::Space space) { 10530 Heap::Space space) {
10464 const OneByteString& result = 10531 const String& result = String::Handle(OneByteString::New(len, space));
10465 OneByteString::Handle(OneByteString::New(len, space)); 10532 String& str = String::Handle();
10466 OneByteString& str = OneByteString::Handle();
10467 intptr_t strings_len = strings.Length(); 10533 intptr_t strings_len = strings.Length();
10468 intptr_t pos = 0; 10534 intptr_t pos = 0;
10469 for (intptr_t i = 0; i < strings_len; i++) { 10535 for (intptr_t i = 0; i < strings_len; i++) {
10470 str ^= strings.At(i); 10536 str ^= strings.At(i);
10471 intptr_t str_len = str.Length(); 10537 intptr_t str_len = str.Length();
10472 String::Copy(result, pos, str, 0, str_len); 10538 String::Copy(result, pos, str, 0, str_len);
10473 pos += str_len; 10539 pos += str_len;
10474 } 10540 }
10475 return result.raw(); 10541 return OneByteString::raw(result);
10476 } 10542 }
10477 10543
10478 10544
10479 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch), 10545 RawOneByteString* OneByteString::Transform(int32_t (*mapping)(int32_t ch),
10480 const String& str, 10546 const String& str,
10481 Heap::Space space) { 10547 Heap::Space space) {
10482 ASSERT(!str.IsNull()); 10548 ASSERT(!str.IsNull());
10483 intptr_t len = str.Length(); 10549 intptr_t len = str.Length();
10484 const OneByteString& result = 10550 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) { 10551 for (intptr_t i = 0; i < len; ++i) {
10487 int32_t ch = mapping(str.CharAt(i)); 10552 int32_t ch = mapping(str.CharAt(i));
10488 ASSERT(ch >= 0 && ch <= 0x7F); 10553 ASSERT(ch >= 0 && ch <= 0x7F);
10489 *result.CharAddr(i) = ch; 10554 *CharAddr(result, i) = ch;
10490 } 10555 }
10491 return result.raw(); 10556 return OneByteString::raw(result);
10492 } 10557 }
10493 10558
10494 10559
10495 const char* OneByteString::ToCString() const { 10560 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str,
10496 return String::ToCString(); 10561 bool raw_str) {
10497 } 10562 intptr_t len = str.Length();
10498
10499
10500 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(bool raw_str) const {
10501 intptr_t len = Length();
10502 if (len > 0) { 10563 if (len > 0) {
10503 intptr_t num_escapes = 0; 10564 intptr_t num_escapes = 0;
10504 intptr_t index = 0; 10565 intptr_t index = 0;
10505 for (intptr_t i = 0; i < len; i++) { 10566 for (intptr_t i = 0; i < len; i++) {
10506 if (IsSpecialCharacter(*CharAddr(i)) || 10567 if (IsSpecialCharacter(*CharAddr(str, i)) ||
10507 (!raw_str && (*CharAddr(i) == '\\'))) { 10568 (!raw_str && (*CharAddr(str, i) == '\\'))) {
10508 num_escapes += 1; 10569 num_escapes += 1;
10509 } 10570 }
10510 } 10571 }
10511 const TwoByteString& dststr = TwoByteString::Handle( 10572 const String& dststr = String::Handle(
10512 TwoByteString::New(len + num_escapes, Heap::kNew)); 10573 TwoByteString::New(len + num_escapes, Heap::kNew));
10513 for (intptr_t i = 0; i < len; i++) { 10574 for (intptr_t i = 0; i < len; i++) {
10514 if (IsSpecialCharacter(*CharAddr(i))) { 10575 if (IsSpecialCharacter(*CharAddr(str, i))) {
10515 *(dststr.CharAddr(index)) = '\\'; 10576 *(CharAddr(dststr, index)) = '\\';
10516 *(dststr.CharAddr(index + 1)) = SpecialCharacter(*CharAddr(i)); 10577 *(CharAddr(dststr, index + 1)) = SpecialCharacter(*CharAddr(str, i));
10517 index += 2; 10578 index += 2;
10518 } else if (!raw_str && (*CharAddr(i) == '\\')) { 10579 } else if (!raw_str && (*CharAddr(str, i) == '\\')) {
10519 *(dststr.CharAddr(index)) = '\\'; 10580 *(CharAddr(dststr, index)) = '\\';
10520 *(dststr.CharAddr(index + 1)) = '\\'; 10581 *(CharAddr(dststr, index + 1)) = '\\';
10521 index += 2; 10582 index += 2;
10522 } else { 10583 } else {
10523 *(dststr.CharAddr(index)) = *CharAddr(i); 10584 *(CharAddr(dststr, index)) = *CharAddr(str, i);
10524 index += 1; 10585 index += 1;
10525 } 10586 }
10526 } 10587 }
10527 return dststr.raw(); 10588 return TwoByteString::raw(dststr);
10528 } 10589 }
10529 return TwoByteString::null(); 10590 return TwoByteString::null();
10530 } 10591 }
10531 10592
10532 10593
10533 RawTwoByteString* TwoByteString::New(intptr_t len, 10594 RawTwoByteString* TwoByteString::New(intptr_t len,
10534 Heap::Space space) { 10595 Heap::Space space) {
10535 ASSERT(Isolate::Current()->object_store()->two_byte_string_class()); 10596 ASSERT(Isolate::Current()->object_store()->two_byte_string_class());
10536 if (len < 0 || len > kMaxElements) { 10597 if (len < 0 || len > kMaxElements) {
10537 // This should be caught before we reach here. 10598 // This should be caught before we reach here.
10538 FATAL1("Fatal error in TwoByteString::New: invalid len %"Pd"\n", len); 10599 FATAL1("Fatal error in TwoByteString::New: invalid len %"Pd"\n", len);
10539 } 10600 }
10540 TwoByteString& result = TwoByteString::Handle(); 10601 String& result = String::Handle();
10541 { 10602 {
10542 RawObject* raw = Object::Allocate(TwoByteString::kClassId, 10603 RawObject* raw = Object::Allocate(TwoByteString::kClassId,
10543 TwoByteString::InstanceSize(len), 10604 TwoByteString::InstanceSize(len),
10544 space); 10605 space);
10545 NoGCScope no_gc; 10606 NoGCScope no_gc;
10546 result ^= raw; 10607 result ^= raw;
10547 result.SetLength(len); 10608 result.SetLength(len);
10548 result.SetHash(0); 10609 result.SetHash(0);
10549 } 10610 }
10550 return result.raw(); 10611 return TwoByteString::raw(result);
10551 } 10612 }
10552 10613
10553 10614
10554 RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array, 10615 RawTwoByteString* TwoByteString::New(const uint16_t* utf16_array,
10555 intptr_t array_len, 10616 intptr_t array_len,
10556 Heap::Space space) { 10617 Heap::Space space) {
10557 ASSERT(array_len > 0); 10618 ASSERT(array_len > 0);
10558 const TwoByteString& result = 10619 const String& result = String::Handle(TwoByteString::New(array_len, space));
10559 TwoByteString::Handle(TwoByteString::New(array_len, space));
10560 { 10620 {
10561 NoGCScope no_gc; 10621 NoGCScope no_gc;
10562 memmove(result.CharAddr(0), utf16_array, (array_len * 2)); 10622 memmove(CharAddr(result, 0), utf16_array, (array_len * 2));
10563 } 10623 }
10564 return result.raw(); 10624 return TwoByteString::raw(result);
10565 } 10625 }
10566 10626
10567 10627
10568 RawTwoByteString* TwoByteString::New(intptr_t utf16_len, 10628 RawTwoByteString* TwoByteString::New(intptr_t utf16_len,
10569 const uint32_t* utf32_array, 10629 const uint32_t* utf32_array,
10570 intptr_t array_len, 10630 intptr_t array_len,
10571 Heap::Space space) { 10631 Heap::Space space) {
10572 ASSERT((array_len > 0) && (utf16_len >= array_len)); 10632 ASSERT((array_len > 0) && (utf16_len >= array_len));
10573 const TwoByteString& result = 10633 const String& result = String::Handle(TwoByteString::New(utf16_len, space));
10574 TwoByteString::Handle(TwoByteString::New(utf16_len, space));
10575 { 10634 {
10576 NoGCScope no_gc; 10635 NoGCScope no_gc;
10577 intptr_t j = 0; 10636 intptr_t j = 0;
10578 for (intptr_t i = 0; i < array_len; ++i) { 10637 for (intptr_t i = 0; i < array_len; ++i) {
10579 if (utf32_array[i] > 0xffff) { 10638 if (utf32_array[i] > 0xffff) {
10580 ASSERT(j < (utf16_len - 1)); 10639 ASSERT(j < (utf16_len - 1));
10581 Utf8::ConvertUTF32ToUTF16(utf32_array[i], result.CharAddr(j)); 10640 Utf8::ConvertUTF32ToUTF16(utf32_array[i], CharAddr(result, j));
10582 j += 2; 10641 j += 2;
10583 } else { 10642 } else {
10584 ASSERT(j < utf16_len); 10643 ASSERT(j < utf16_len);
10585 *result.CharAddr(j) = utf32_array[i]; 10644 *CharAddr(result, j) = utf32_array[i];
10586 j += 1; 10645 j += 1;
10587 } 10646 }
10588 } 10647 }
10589 } 10648 }
10590 return result.raw(); 10649 return TwoByteString::raw(result);
10591 } 10650 }
10592 10651
10593 10652
10594 RawTwoByteString* TwoByteString::New(const TwoByteString& str, 10653 RawTwoByteString* TwoByteString::New(const String& str,
10595 Heap::Space space) { 10654 Heap::Space space) {
10596 intptr_t len = str.Length(); 10655 intptr_t len = str.Length();
10597 const TwoByteString& result = 10656 const String& result = String::Handle(TwoByteString::New(len, space));
10598 TwoByteString::Handle(TwoByteString::New(len, space));
10599 String::Copy(result, 0, str, 0, len); 10657 String::Copy(result, 0, str, 0, len);
10600 return result.raw(); 10658 return TwoByteString::raw(result);
10601 } 10659 }
10602 10660
10603 10661
10604 RawTwoByteString* TwoByteString::Concat(const String& str1, 10662 RawTwoByteString* TwoByteString::Concat(const String& str1,
10605 const String& str2, 10663 const String& str2,
10606 Heap::Space space) { 10664 Heap::Space space) {
10607 intptr_t len1 = str1.Length(); 10665 intptr_t len1 = str1.Length();
10608 intptr_t len2 = str2.Length(); 10666 intptr_t len2 = str2.Length();
10609 intptr_t len = len1 + len2; 10667 intptr_t len = len1 + len2;
10610 const TwoByteString& result = 10668 const String& result = String::Handle(TwoByteString::New(len, space));
10611 TwoByteString::Handle(TwoByteString::New(len, space));
10612 String::Copy(result, 0, str1, 0, len1); 10669 String::Copy(result, 0, str1, 0, len1);
10613 String::Copy(result, len1, str2, 0, len2); 10670 String::Copy(result, len1, str2, 0, len2);
10614 return result.raw(); 10671 return TwoByteString::raw(result);
10615 } 10672 }
10616 10673
10617 10674
10618 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings, 10675 RawTwoByteString* TwoByteString::ConcatAll(const Array& strings,
10619 intptr_t len, 10676 intptr_t len,
10620 Heap::Space space) { 10677 Heap::Space space) {
10621 const TwoByteString& result = 10678 const String& result = String::Handle(TwoByteString::New(len, space));
10622 TwoByteString::Handle(TwoByteString::New(len, space));
10623 String& str = String::Handle(); 10679 String& str = String::Handle();
10624 intptr_t strings_len = strings.Length(); 10680 intptr_t strings_len = strings.Length();
10625 intptr_t pos = 0; 10681 intptr_t pos = 0;
10626 for (intptr_t i = 0; i < strings_len; i++) { 10682 for (intptr_t i = 0; i < strings_len; i++) {
10627 str ^= strings.At(i); 10683 str ^= strings.At(i);
10628 intptr_t str_len = str.Length(); 10684 intptr_t str_len = str.Length();
10629 String::Copy(result, pos, str, 0, str_len); 10685 String::Copy(result, pos, str, 0, str_len);
10630 pos += str_len; 10686 pos += str_len;
10631 } 10687 }
10632 return result.raw(); 10688 return TwoByteString::raw(result);
10633 } 10689 }
10634 10690
10635 10691
10636 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch), 10692 RawTwoByteString* TwoByteString::Transform(int32_t (*mapping)(int32_t ch),
10637 const String& str, 10693 const String& str,
10638 Heap::Space space) { 10694 Heap::Space space) {
10639 ASSERT(!str.IsNull()); 10695 ASSERT(!str.IsNull());
10640 intptr_t len = str.Length(); 10696 intptr_t len = str.Length();
10641 const TwoByteString& result = 10697 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) { 10698 for (intptr_t i = 0; i < len; ++i) {
10644 int32_t ch = mapping(str.CharAt(i)); 10699 int32_t ch = mapping(str.CharAt(i));
10645 ASSERT(ch >= 0 && ch <= 0xFFFF); 10700 ASSERT(ch >= 0 && ch <= 0xFFFF);
10646 *result.CharAddr(i) = ch; 10701 *CharAddr(result, i) = ch;
10647 } 10702 }
10648 return result.raw(); 10703 return TwoByteString::raw(result);
10649 } 10704 }
10650 10705
10651 10706
10652 const char* TwoByteString::ToCString() const {
10653 return String::ToCString();
10654 }
10655
10656
10657 static void AddFinalizer(const Object& referent, 10707 static void AddFinalizer(const Object& referent,
10658 void* peer, 10708 void* peer,
10659 Dart_WeakPersistentHandleFinalizer callback) { 10709 Dart_WeakPersistentHandleFinalizer callback) {
10660 ASSERT(callback != NULL); 10710 ASSERT(callback != NULL);
10661 ApiState* state = Isolate::Current()->api_state(); 10711 ApiState* state = Isolate::Current()->api_state();
10662 ASSERT(state != NULL); 10712 ASSERT(state != NULL);
10663 FinalizablePersistentHandle* weak_ref = 10713 FinalizablePersistentHandle* weak_ref =
10664 state->weak_persistent_handles().AllocateHandle(); 10714 state->weak_persistent_handles().AllocateHandle();
10665 weak_ref->set_raw(referent); 10715 weak_ref->set_raw(referent);
10666 weak_ref->set_peer(peer); 10716 weak_ref->set_peer(peer);
10667 weak_ref->set_callback(callback); 10717 weak_ref->set_callback(callback);
10668 } 10718 }
10669 10719
10670 10720
10671 RawExternalOneByteString* ExternalOneByteString::New( 10721 RawExternalOneByteString* ExternalOneByteString::New(
10672 const uint8_t* data, 10722 const uint8_t* data,
10673 intptr_t len, 10723 intptr_t len,
10674 void* peer, 10724 void* peer,
10675 Dart_PeerFinalizer callback, 10725 Dart_PeerFinalizer callback,
10676 Heap::Space space) { 10726 Heap::Space space) {
10677 ASSERT(Isolate::Current()->object_store()->external_one_byte_string_class() != 10727 ASSERT(Isolate::Current()->object_store()->
10678 Class::null()); 10728 external_one_byte_string_class() != Class::null());
10679 if (len < 0 || len > kMaxElements) { 10729 if (len < 0 || len > kMaxElements) {
10680 // This should be caught before we reach here. 10730 // This should be caught before we reach here.
10681 FATAL1("Fatal error in ExternalOneByteString::New: invalid len %"Pd"\n", 10731 FATAL1("Fatal error in ExternalOneByteString::New: invalid len %"Pd"\n",
10682 len); 10732 len);
10683 } 10733 }
10684 ExternalOneByteString& result = ExternalOneByteString::Handle(); 10734 String& result = String::Handle();
10685 ExternalStringData<uint8_t>* external_data = 10735 ExternalStringData<uint8_t>* external_data =
10686 new ExternalStringData<uint8_t>(data, peer, callback); 10736 new ExternalStringData<uint8_t>(data, peer, callback);
10687 { 10737 {
10688 RawObject* raw = Object::Allocate(ExternalOneByteString::kClassId, 10738 RawObject* raw = Object::Allocate(ExternalOneByteString::kClassId,
10689 ExternalOneByteString::InstanceSize(), 10739 ExternalOneByteString::InstanceSize(),
10690 space); 10740 space);
10691 NoGCScope no_gc; 10741 NoGCScope no_gc;
10692 result ^= raw; 10742 result ^= raw;
10693 result.SetLength(len); 10743 result.SetLength(len);
10694 result.SetHash(0); 10744 result.SetHash(0);
10695 result.SetExternalData(external_data); 10745 SetExternalData(result, external_data);
10696 } 10746 }
10697 AddFinalizer(result, external_data, ExternalOneByteString::Finalize); 10747 AddFinalizer(result, external_data, ExternalOneByteString::Finalize);
10698 return result.raw(); 10748 return ExternalOneByteString::raw(result);
10699 } 10749 }
10700 10750
10701 10751
10702 static void DeleteWeakPersistentHandle(Dart_Handle handle) { 10752 static void DeleteWeakPersistentHandle(Dart_Handle handle) {
10703 ApiState* state = Isolate::Current()->api_state(); 10753 ApiState* state = Isolate::Current()->api_state();
10704 ASSERT(state != NULL); 10754 ASSERT(state != NULL);
10705 FinalizablePersistentHandle* weak_ref = 10755 FinalizablePersistentHandle* weak_ref =
10706 reinterpret_cast<FinalizablePersistentHandle*>(handle); 10756 reinterpret_cast<FinalizablePersistentHandle*>(handle);
10707 ASSERT(state->IsValidWeakPersistentHandle(handle)); 10757 ASSERT(state->IsValidWeakPersistentHandle(handle));
10708 state->weak_persistent_handles().FreeHandle(weak_ref); 10758 state->weak_persistent_handles().FreeHandle(weak_ref);
10709 } 10759 }
10710 10760
10711 10761
10712 void ExternalOneByteString::Finalize(Dart_Handle handle, void* peer) { 10762 void ExternalOneByteString::Finalize(Dart_Handle handle, void* peer) {
10713 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); 10763 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer);
10714 DeleteWeakPersistentHandle(handle); 10764 DeleteWeakPersistentHandle(handle);
10715 } 10765 }
10716 10766
10717 10767
10718 const char* ExternalOneByteString::ToCString() const {
10719 return String::ToCString();
10720 }
10721
10722
10723 RawExternalTwoByteString* ExternalTwoByteString::New( 10768 RawExternalTwoByteString* ExternalTwoByteString::New(
10724 const uint16_t* data, 10769 const uint16_t* data,
10725 intptr_t len, 10770 intptr_t len,
10726 void* peer, 10771 void* peer,
10727 Dart_PeerFinalizer callback, 10772 Dart_PeerFinalizer callback,
10728 Heap::Space space) { 10773 Heap::Space space) {
10729 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != 10774 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() !=
10730 Class::null()); 10775 Class::null());
10731 if (len < 0 || len > kMaxElements) { 10776 if (len < 0 || len > kMaxElements) {
10732 // This should be caught before we reach here. 10777 // This should be caught before we reach here.
10733 FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %"Pd"\n", 10778 FATAL1("Fatal error in ExternalTwoByteString::New: invalid len %"Pd"\n",
10734 len); 10779 len);
10735 } 10780 }
10736 ExternalTwoByteString& result = ExternalTwoByteString::Handle(); 10781 String& result = String::Handle();
10737 ExternalStringData<uint16_t>* external_data = 10782 ExternalStringData<uint16_t>* external_data =
10738 new ExternalStringData<uint16_t>(data, peer, callback); 10783 new ExternalStringData<uint16_t>(data, peer, callback);
10739 { 10784 {
10740 RawObject* raw = Object::Allocate(ExternalTwoByteString::kClassId, 10785 RawObject* raw = Object::Allocate(ExternalTwoByteString::kClassId,
10741 ExternalTwoByteString::InstanceSize(), 10786 ExternalTwoByteString::InstanceSize(),
10742 space); 10787 space);
10743 NoGCScope no_gc; 10788 NoGCScope no_gc;
10744 result ^= raw; 10789 result ^= raw;
10745 result.SetLength(len); 10790 result.SetLength(len);
10746 result.SetHash(0); 10791 result.SetHash(0);
10747 result.SetExternalData(external_data); 10792 SetExternalData(result, external_data);
10748 } 10793 }
10749 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize); 10794 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize);
10750 return result.raw(); 10795 return ExternalTwoByteString::raw(result);
10751 } 10796 }
10752 10797
10753 10798
10754 void ExternalTwoByteString::Finalize(Dart_Handle handle, void* peer) { 10799 void ExternalTwoByteString::Finalize(Dart_Handle handle, void* peer) {
10755 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); 10800 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer);
10756 DeleteWeakPersistentHandle(handle); 10801 DeleteWeakPersistentHandle(handle);
10757 } 10802 }
10758 10803
10759 10804
10760 const char* ExternalTwoByteString::ToCString() const {
10761 return String::ToCString();
10762 }
10763
10764
10765 RawBool* Bool::True() { 10805 RawBool* Bool::True() {
10766 return Isolate::Current()->object_store()->true_value(); 10806 return Isolate::Current()->object_store()->true_value();
10767 } 10807 }
10768 10808
10769 10809
10770 RawBool* Bool::False() { 10810 RawBool* Bool::False() {
10771 return Isolate::Current()->object_store()->false_value(); 10811 return Isolate::Current()->object_store()->false_value();
10772 } 10812 }
10773 10813
10774 10814
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
11893 } 11933 }
11894 return result.raw(); 11934 return result.raw();
11895 } 11935 }
11896 11936
11897 11937
11898 const char* WeakProperty::ToCString() const { 11938 const char* WeakProperty::ToCString() const {
11899 return "_WeakProperty"; 11939 return "_WeakProperty";
11900 } 11940 }
11901 11941
11902 } // namespace dart 11942 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698