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

Side by Side Diff: vm/object.cc

Issue 11969029: Allow externalization of canonical strings also. Only restrict canonical strings (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 11 months 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 | « vm/object.h ('k') | 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 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 if (name.CharAt(j) != accessor_name.CharAt(i)) { 2258 if (name.CharAt(j) != accessor_name.CharAt(i)) {
2259 return false; 2259 return false;
2260 } 2260 }
2261 } 2261 }
2262 return true; 2262 return true;
2263 } 2263 }
2264 2264
2265 2265
2266 RawFunction* Class::LookupFunction(const String& name) const { 2266 RawFunction* Class::LookupFunction(const String& name) const {
2267 Isolate* isolate = Isolate::Current(); 2267 Isolate* isolate = Isolate::Current();
2268 ASSERT(name.IsOneByteString()); 2268 ASSERT(name.IsOneByteString() || name.IsExternalOneByteString());
Ivan Posva 2013/01/17 07:19:39 I do not understand why we are limiting this to on
2269 Array& funcs = Array::Handle(isolate, functions()); 2269 Array& funcs = Array::Handle(isolate, functions());
2270 if (funcs.IsNull()) { 2270 if (funcs.IsNull()) {
2271 // This can occur, e.g., for Null classes. 2271 // This can occur, e.g., for Null classes.
2272 return Function::null(); 2272 return Function::null();
2273 } 2273 }
2274 Function& function = Function::Handle(isolate, Function::null()); 2274 Function& function = Function::Handle(isolate, Function::null());
2275 if (name.IsSymbol()) { 2275 if (name.IsSymbol()) {
2276 // Quick Symbol compare. 2276 // Quick Symbol compare.
2277 intptr_t len = funcs.Length(); 2277 intptr_t len = funcs.Length();
2278 for (intptr_t i = 0; i < len; i++) { 2278 for (intptr_t i = 0; i < len; i++) {
(...skipping 13 matching lines...) Expand all
2292 } 2292 }
2293 } 2293 }
2294 } 2294 }
2295 // No function found. 2295 // No function found.
2296 return Function::null(); 2296 return Function::null();
2297 } 2297 }
2298 2298
2299 2299
2300 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const { 2300 RawFunction* Class::LookupFunctionAllowPrivate(const String& name) const {
2301 Isolate* isolate = Isolate::Current(); 2301 Isolate* isolate = Isolate::Current();
2302 ASSERT(name.IsOneByteString()); 2302 ASSERT(name.IsOneByteString() || name.IsExternalOneByteString());
2303 Array& funcs = Array::Handle(isolate, functions()); 2303 Array& funcs = Array::Handle(isolate, functions());
2304 if (funcs.IsNull()) { 2304 if (funcs.IsNull()) {
2305 // This can occur, e.g., for Null classes. 2305 // This can occur, e.g., for Null classes.
2306 return Function::null(); 2306 return Function::null();
2307 } 2307 }
2308 Function& function = Function::Handle(isolate, Function::null()); 2308 Function& function = Function::Handle(isolate, Function::null());
2309 String& function_name = String::Handle(isolate, String::null()); 2309 String& function_name = String::Handle(isolate, String::null());
2310 intptr_t len = funcs.Length(); 2310 intptr_t len = funcs.Length();
2311 for (intptr_t i = 0; i < len; i++) { 2311 for (intptr_t i = 0; i < len; i++) {
2312 function ^= funcs.At(i); 2312 function ^= funcs.At(i);
2313 function_name ^= function.name(); 2313 function_name ^= function.name();
2314 if (OneByteString::EqualsIgnoringPrivateKey(function_name, name)) { 2314 if (String::EqualsIgnoringPrivateKey(function_name, name)) {
2315 return function.raw(); 2315 return function.raw();
2316 } 2316 }
2317 } 2317 }
2318 // No function found. 2318 // No function found.
2319 return Function::null(); 2319 return Function::null();
2320 } 2320 }
2321 2321
2322 2322
2323 RawFunction* Class::LookupGetterFunction(const String& name) const { 2323 RawFunction* Class::LookupGetterFunction(const String& name) const {
2324 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); 2324 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name);
2325 } 2325 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2398 } 2398 }
2399 return field.raw(); 2399 return field.raw();
2400 } 2400 }
2401 // No field found. 2401 // No field found.
2402 return Field::null(); 2402 return Field::null();
2403 } 2403 }
2404 2404
2405 2405
2406 RawField* Class::LookupField(const String& name) const { 2406 RawField* Class::LookupField(const String& name) const {
2407 Isolate* isolate = Isolate::Current(); 2407 Isolate* isolate = Isolate::Current();
2408 ASSERT(name.IsOneByteString()); 2408 ASSERT(name.IsOneByteString() || name.IsExternalOneByteString());
2409 const Array& flds = Array::Handle(isolate, fields()); 2409 const Array& flds = Array::Handle(isolate, fields());
2410 Field& field = Field::Handle(isolate, Field::null()); 2410 Field& field = Field::Handle(isolate, Field::null());
2411 String& field_name = String::Handle(isolate, String::null()); 2411 String& field_name = String::Handle(isolate, String::null());
2412 intptr_t len = flds.Length(); 2412 intptr_t len = flds.Length();
2413 for (intptr_t i = 0; i < len; i++) { 2413 for (intptr_t i = 0; i < len; i++) {
2414 field ^= flds.At(i); 2414 field ^= flds.At(i);
2415 field_name ^= field.name(); 2415 field_name ^= field.name();
2416 if (OneByteString::EqualsIgnoringPrivateKey(field_name, name)) { 2416 if (String::EqualsIgnoringPrivateKey(field_name, name)) {
2417 return field.raw(); 2417 return field.raw();
2418 } 2418 }
2419 } 2419 }
2420 // No field found. 2420 // No field found.
2421 return Field::null(); 2421 return Field::null();
2422 } 2422 }
2423 2423
2424 2424
2425 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { 2425 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const {
2426 Isolate* isolate = Isolate::Current(); 2426 Isolate* isolate = Isolate::Current();
2427 const Library& lib = Library::Handle(isolate, library()); 2427 const Library& lib = Library::Handle(isolate, library());
(...skipping 8425 matching lines...) Expand 10 before | Expand all | Expand 10 after
10853 Dart_PeerFinalizer cback) const { 10853 Dart_PeerFinalizer cback) const {
10854 NoGCScope no_gc; 10854 NoGCScope no_gc;
10855 ASSERT(array != NULL); 10855 ASSERT(array != NULL);
10856 intptr_t str_length = this->Length(); 10856 intptr_t str_length = this->Length();
10857 ASSERT(length >= (str_length * this->CharSize())); 10857 ASSERT(length >= (str_length * this->CharSize()));
10858 intptr_t class_id = raw()->GetClassId(); 10858 intptr_t class_id = raw()->GetClassId();
10859 intptr_t used_size = 0; 10859 intptr_t used_size = 0;
10860 intptr_t original_size = 0; 10860 intptr_t original_size = 0;
10861 uword tags = raw_ptr()->tags_; 10861 uword tags = raw_ptr()->tags_;
10862 10862
10863 ASSERT(!IsCanonical()); 10863 ASSERT(!InVMHeap());
10864 if (class_id == kOneByteStringCid) { 10864 if (class_id == kOneByteStringCid) {
10865 used_size = ExternalOneByteString::InstanceSize(); 10865 used_size = ExternalOneByteString::InstanceSize();
10866 original_size = OneByteString::InstanceSize(str_length); 10866 original_size = OneByteString::InstanceSize(str_length);
10867 ASSERT(original_size >= used_size); 10867 ASSERT(original_size >= used_size);
10868 10868
10869 // Copy the data into the external array. 10869 // Copy the data into the external array.
10870 if (str_length > 0) { 10870 if (str_length > 0) {
10871 memmove(array, OneByteString::CharAddr(*this, 0), str_length); 10871 memmove(array, OneByteString::CharAddr(*this, 0), str_length);
10872 } 10872 }
10873 10873
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
10950 return Transform(CaseMapping::ToUpper, str, space); 10950 return Transform(CaseMapping::ToUpper, str, space);
10951 } 10951 }
10952 10952
10953 10953
10954 RawString* String::ToLowerCase(const String& str, Heap::Space space) { 10954 RawString* String::ToLowerCase(const String& str, Heap::Space space) {
10955 // TODO(cshapiro): create a fast-path for OneByteString instances. 10955 // TODO(cshapiro): create a fast-path for OneByteString instances.
10956 return Transform(CaseMapping::ToLower, str, space); 10956 return Transform(CaseMapping::ToLower, str, space);
10957 } 10957 }
10958 10958
10959 10959
10960 // Check to see if 'str1' matches 'str2' as is or
10961 // once the private key separator is stripped from str2.
10962 //
10963 // Things are made more complicated by the fact that constructors are
10964 // added *after* the private suffix, so "foo@123.named" should match
10965 // "foo.named".
10966 //
10967 // Also, the private suffix can occur more than once in the name, as in:
10968 //
10969 // _ReceivePortImpl@6be832b._internal@6be832b
10970 //
10971 template<typename T1, typename T2>
10972 static bool EqualsIgnoringPrivateKey(const String& str1,
10973 const String& str2) {
10974 NoGCScope no_gc;
10975 intptr_t len = str1.Length();
10976 intptr_t str2_len = str2.Length();
10977 if (len == str2_len) {
10978 for (intptr_t i = 0; i < len; i++) {
10979 if (T1::CharAt(str1, i) != T2::CharAt(str2, i)) {
10980 return false;
10981 }
10982 }
10983 return true;
10984 }
10985 if (len < str2_len) {
10986 return false; // No way they can match.
10987 }
10988 intptr_t pos = 0;
10989 intptr_t str2_pos = 0;
10990 while (pos < len) {
10991 int32_t ch = T1::CharAt(str1, pos);
10992 pos++;
10993
10994 if (ch == Scanner::kPrivateKeySeparator) {
10995 // Consume a private key separator.
10996 while ((pos < len) && (T1::CharAt(str1, pos) != '.')) {
10997 pos++;
10998 }
10999 // Resume matching characters.
11000 continue;
11001 }
11002 if ((str2_pos == str2_len) || (ch != T2::CharAt(str2, str2_pos))) {
11003 return false;
11004 }
11005 str2_pos++;
11006 }
11007
11008 // We have reached the end of mangled_name string.
11009 ASSERT(pos == len);
11010 return (str2_pos == str2_len);
11011 }
11012
11013
11014 bool String::EqualsIgnoringPrivateKey(const String& str1,
11015 const String& str2) {
11016 if (str1.raw() == str2.raw()) {
11017 return true; // Both handles point to the same raw instance.
11018 }
11019 if (str1.IsOneByteString()) {
11020 if (str2.IsOneByteString()) {
11021 return dart::EqualsIgnoringPrivateKey<OneByteString,
11022 OneByteString>(str1, str2);
11023 }
11024 ASSERT(str2.IsExternalOneByteString());
11025 return dart::EqualsIgnoringPrivateKey<OneByteString,
11026 ExternalOneByteString>(str1, str2);
11027 }
11028 ASSERT(str1.IsExternalOneByteString());
11029 if (str2.IsOneByteString()) {
11030 return dart::EqualsIgnoringPrivateKey<ExternalOneByteString,
11031 OneByteString>(str1, str2);
11032 }
11033 ASSERT(str2.IsExternalOneByteString());
11034 return dart::EqualsIgnoringPrivateKey<ExternalOneByteString,
11035 ExternalOneByteString>(str1, str2);
11036 }
11037
11038
10960 bool String::CodePointIterator::Next() { 11039 bool String::CodePointIterator::Next() {
10961 ASSERT(index_ >= -1); 11040 ASSERT(index_ >= -1);
10962 intptr_t length = Utf16::Length(ch_); 11041 intptr_t length = Utf16::Length(ch_);
10963 if (index_ < (end_ - length)) { 11042 if (index_ < (end_ - length)) {
10964 index_ += length; 11043 index_ += length;
10965 ch_ = str_.CharAt(index_); 11044 ch_ = str_.CharAt(index_);
10966 if (Utf16::IsLeadSurrogate(ch_) && (index_ < (end_ - 1))) { 11045 if (Utf16::IsLeadSurrogate(ch_) && (index_ < (end_ - 1))) {
10967 int32_t ch2 = str_.CharAt(index_ + 1); 11046 int32_t ch2 = str_.CharAt(index_ + 1);
10968 if (Utf16::IsTrailSurrogate(ch2)) { 11047 if (Utf16::IsTrailSurrogate(ch2)) {
10969 ch_ = Utf16::Decode(ch_, ch2); 11048 ch_ = Utf16::Decode(ch_, ch2);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
11003 *(CharAddr(dststr, index)) = *CharAddr(str, i); 11082 *(CharAddr(dststr, index)) = *CharAddr(str, i);
11004 index += 1; 11083 index += 1;
11005 } 11084 }
11006 } 11085 }
11007 return OneByteString::raw(dststr); 11086 return OneByteString::raw(dststr);
11008 } 11087 }
11009 return OneByteString::null(); 11088 return OneByteString::null();
11010 } 11089 }
11011 11090
11012 11091
11013 // Check to see if 'str1' matches 'str2' as is or
11014 // once the private key separator is stripped from str2.
11015 //
11016 // Things are made more complicated by the fact that constructors are
11017 // added *after* the private suffix, so "foo@123.named" should match
11018 // "foo.named".
11019 //
11020 // Also, the private suffix can occur more than once in the name, as in:
11021 //
11022 // _ReceivePortImpl@6be832b._internal@6be832b
11023 //
11024 bool OneByteString::EqualsIgnoringPrivateKey(const String& str1,
11025 const String& str2) {
11026 ASSERT(str2.IsOneByteString());
11027 if (str1.raw() == str2.raw()) {
11028 return true; // Both handles point to the same raw instance.
11029 }
11030 NoGCScope no_gc;
11031 intptr_t len = str1.Length();
11032 intptr_t str2_len = str2.Length();
11033 if (len == str2_len) {
11034 for (intptr_t i = 0; i < len; i++) {
11035 if (*CharAddr(str1, i) != *CharAddr(str2, i)) {
11036 return false;
11037 }
11038 }
11039 return true;
11040 }
11041 if (len < str2_len) {
11042 return false; // No way they can match.
11043 }
11044 intptr_t pos = 0;
11045 intptr_t str2_pos = 0;
11046 while (pos < len) {
11047 int32_t ch = *CharAddr(str1, pos);
11048 pos++;
11049
11050 if (ch == Scanner::kPrivateKeySeparator) {
11051 // Consume a private key separator.
11052 while ((pos < len) && (*CharAddr(str1, pos) != '.')) {
11053 pos++;
11054 }
11055 // Resume matching characters.
11056 continue;
11057 }
11058 if ((str2_pos == str2_len) || (ch != *CharAddr(str2, str2_pos))) {
11059 return false;
11060 }
11061 str2_pos++;
11062 }
11063
11064 // We have reached the end of mangled_name string.
11065 ASSERT(pos == len);
11066 return (str2_pos == str2_len);
11067 }
11068
11069
11070 RawOneByteString* OneByteString::New(intptr_t len, 11092 RawOneByteString* OneByteString::New(intptr_t len,
11071 Heap::Space space) { 11093 Heap::Space space) {
11072 ASSERT(Isolate::Current() == Dart::vm_isolate() || 11094 ASSERT(Isolate::Current() == Dart::vm_isolate() ||
11073 Isolate::Current()->object_store()->one_byte_string_class() != 11095 Isolate::Current()->object_store()->one_byte_string_class() !=
11074 Class::null()); 11096 Class::null());
11075 if (len < 0 || len > kMaxElements) { 11097 if (len < 0 || len > kMaxElements) {
11076 // This should be caught before we reach here. 11098 // This should be caught before we reach here.
11077 FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len); 11099 FATAL1("Fatal error in OneByteString::New: invalid len %"Pd"\n", len);
11078 } 11100 }
11079 String& result = String::Handle(); 11101 String& result = String::Handle();
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after
12595 } 12617 }
12596 return result.raw(); 12618 return result.raw();
12597 } 12619 }
12598 12620
12599 12621
12600 const char* WeakProperty::ToCString() const { 12622 const char* WeakProperty::ToCString() const {
12601 return "_WeakProperty"; 12623 return "_WeakProperty";
12602 } 12624 }
12603 12625
12604 } // namespace dart 12626 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.h ('k') | vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698