Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 4143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4154 return Field::null(); | 4154 return Field::null(); |
| 4155 } | 4155 } |
| 4156 REUSABLE_ARRAY_HANDLESCOPE(thread); | 4156 REUSABLE_ARRAY_HANDLESCOPE(thread); |
| 4157 REUSABLE_FIELD_HANDLESCOPE(thread); | 4157 REUSABLE_FIELD_HANDLESCOPE(thread); |
| 4158 REUSABLE_STRING_HANDLESCOPE(thread); | 4158 REUSABLE_STRING_HANDLESCOPE(thread); |
| 4159 Array& flds = thread->ArrayHandle(); | 4159 Array& flds = thread->ArrayHandle(); |
| 4160 flds ^= fields(); | 4160 flds ^= fields(); |
| 4161 ASSERT(!flds.IsNull()); | 4161 ASSERT(!flds.IsNull()); |
| 4162 intptr_t len = flds.Length(); | 4162 intptr_t len = flds.Length(); |
| 4163 Field& field = thread->FieldHandle(); | 4163 Field& field = thread->FieldHandle(); |
| 4164 if (name.IsSymbol()) { | |
| 4165 // Use fast raw pointer string compare for symbols. | |
| 4166 for (intptr_t i = 0; i < len; i++) { | |
| 4167 field ^= flds.At(i); | |
| 4168 if (name.raw() == field.name()) { | |
| 4169 if (kind == kInstance) { | |
| 4170 return field.is_static() ? Field::null() : field.raw(); | |
| 4171 } else if (kind == kStatic) { | |
| 4172 return field.is_static() ? field.raw() : Field::null(); | |
| 4173 } | |
| 4174 ASSERT(kind == kAny); | |
| 4175 return field.raw(); | |
| 4176 } | |
| 4177 } | |
| 4178 } else { | |
| 4179 String& field_name = thread->StringHandle(); | |
| 4180 for (intptr_t i = 0; i < len; i++) { | |
| 4181 field ^= flds.At(i); | |
| 4182 field_name ^= field.name(); | |
| 4183 if (name.Equals(field_name)) { | |
| 4184 if (kind == kInstance) { | |
| 4185 return field.is_static() ? Field::null() : field.raw(); | |
| 4186 } else if (kind == kStatic) { | |
| 4187 return field.is_static() ? field.raw() : Field::null(); | |
| 4188 } | |
| 4189 ASSERT(kind == kAny); | |
| 4190 return field.raw(); | |
|
siva
2016/04/07 22:51:30
Not sure if it is worth extracting the code inside
hausner
2016/04/07 23:37:03
I hesitate to create a mini function to factor out
| |
| 4191 } | |
| 4192 } | |
| 4193 } | |
| 4194 return Field::null(); | |
| 4195 } | |
| 4196 | |
| 4197 | |
| 4198 RawField* Class::LookupFieldAllowPrivate(const String& name) const { | |
| 4199 // Use slow string compare, ignoring privacy name mangling. | |
| 4200 Thread* thread = Thread::Current(); | |
| 4201 if (EnsureIsFinalized(thread) != Error::null()) { | |
| 4202 return Field::null(); | |
| 4203 } | |
| 4204 REUSABLE_ARRAY_HANDLESCOPE(thread); | |
| 4205 REUSABLE_FIELD_HANDLESCOPE(thread); | |
| 4206 REUSABLE_STRING_HANDLESCOPE(thread); | |
| 4207 Array& flds = thread->ArrayHandle(); | |
| 4208 flds ^= fields(); | |
| 4209 ASSERT(!flds.IsNull()); | |
| 4210 intptr_t len = flds.Length(); | |
| 4211 Field& field = thread->FieldHandle(); | |
| 4164 String& field_name = thread->StringHandle(); | 4212 String& field_name = thread->StringHandle(); |
| 4165 for (intptr_t i = 0; i < len; i++) { | 4213 for (intptr_t i = 0; i < len; i++) { |
| 4166 field ^= flds.At(i); | 4214 field ^= flds.At(i); |
| 4167 field_name ^= field.name(); | 4215 field_name ^= field.name(); |
| 4168 if (String::EqualsIgnoringPrivateKey(field_name, name)) { | 4216 if (String::EqualsIgnoringPrivateKey(field_name, name)) { |
| 4169 if (kind == kInstance) { | 4217 return field.raw(); |
| 4170 if (!field.is_static()) { | |
| 4171 return field.raw(); | |
| 4172 } | |
| 4173 } else if (kind == kStatic) { | |
| 4174 if (field.is_static()) { | |
| 4175 return field.raw(); | |
| 4176 } | |
| 4177 } else if (kind == kAny) { | |
| 4178 return field.raw(); | |
| 4179 } | |
| 4180 return Field::null(); | |
| 4181 } | 4218 } |
| 4182 } | 4219 } |
| 4183 // No field found. | |
| 4184 return Field::null(); | 4220 return Field::null(); |
| 4185 } | 4221 } |
| 4186 | 4222 |
| 4223 | |
| 4224 RawField* Class::LookupInstanceFieldAllowPrivate(const String& name) const { | |
| 4225 Field& field = Field::Handle(LookupFieldAllowPrivate(name)); | |
| 4226 if (!field.IsNull() && !field.is_static()) { | |
| 4227 return field.raw(); | |
| 4228 } | |
| 4229 return Field::null(); | |
| 4230 } | |
| 4231 | |
| 4232 | |
| 4233 RawField* Class::LookupStaticFieldAllowPrivate(const String& name) const { | |
| 4234 Field& field = Field::Handle(LookupFieldAllowPrivate(name)); | |
| 4235 if (!field.IsNull() && field.is_static()) { | |
| 4236 return field.raw(); | |
| 4237 } | |
| 4238 return Field::null(); | |
| 4239 } | |
| 4240 | |
| 4187 | 4241 |
| 4188 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { | 4242 RawLibraryPrefix* Class::LookupLibraryPrefix(const String& name) const { |
| 4189 Zone* zone = Thread::Current()->zone(); | 4243 Zone* zone = Thread::Current()->zone(); |
| 4190 const Library& lib = Library::Handle(zone, library()); | 4244 const Library& lib = Library::Handle(zone, library()); |
| 4191 const Object& obj = Object::Handle(zone, lib.LookupLocalObject(name)); | 4245 const Object& obj = Object::Handle(zone, lib.LookupLocalObject(name)); |
| 4192 if (!obj.IsNull() && obj.IsLibraryPrefix()) { | 4246 if (!obj.IsNull() && obj.IsLibraryPrefix()) { |
| 4193 return LibraryPrefix::Cast(obj).raw(); | 4247 return LibraryPrefix::Cast(obj).raw(); |
| 4194 } | 4248 } |
| 4195 return LibraryPrefix::null(); | 4249 return LibraryPrefix::null(); |
| 4196 } | 4250 } |
| (...skipping 5210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9407 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); | 9461 ASSERT(Array::Cast(metadata).raw() != Object::empty_array().raw()); |
| 9408 field.SetStaticValue(Array::Cast(metadata), true); | 9462 field.SetStaticValue(Array::Cast(metadata), true); |
| 9409 } | 9463 } |
| 9410 } | 9464 } |
| 9411 return metadata.raw(); | 9465 return metadata.raw(); |
| 9412 } | 9466 } |
| 9413 | 9467 |
| 9414 | 9468 |
| 9415 static bool ShouldBePrivate(const String& name) { | 9469 static bool ShouldBePrivate(const String& name) { |
| 9416 return | 9470 return |
| 9417 (name.Length() >= 1 && | 9471 (name.Length() >= 1 && name.CharAt(0) == '_') || |
| 9418 name.CharAt(0) == '_') || | |
| 9419 (name.Length() >= 5 && | 9472 (name.Length() >= 5 && |
| 9420 (name.CharAt(4) == '_' && | 9473 (name.CharAt(4) == '_' && |
| 9421 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && | 9474 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') && |
| 9422 name.CharAt(1) == 'e' && | 9475 name.CharAt(1) == 'e' && |
| 9423 name.CharAt(2) == 't' && | 9476 name.CharAt(2) == 't' && |
| 9424 name.CharAt(3) == ':')); | 9477 name.CharAt(3) == ':')); |
|
sra1
2016/04/08 20:30:06
Testing ':' before 'g' / 's' will fail faster.
hausner
2016/04/08 20:41:20
The test (name.CharAt(4) == '_') eliminates practi
| |
| 9425 } | 9478 } |
| 9426 | 9479 |
| 9427 | 9480 |
| 9428 RawObject* Library::ResolveName(const String& name) const { | 9481 RawObject* Library::ResolveName(const String& name) const { |
| 9429 Object& obj = Object::Handle(); | 9482 Object& obj = Object::Handle(); |
| 9430 if (FLAG_use_lib_cache && LookupResolvedNamesCache(name, &obj)) { | 9483 if (FLAG_use_lib_cache && LookupResolvedNamesCache(name, &obj)) { |
| 9431 return obj.raw(); | 9484 return obj.raw(); |
| 9432 } | 9485 } |
| 9433 obj = LookupLocalObject(name); | 9486 obj = LookupLocalObject(name); |
| 9434 if (!obj.IsNull()) { | 9487 if (!obj.IsNull()) { |
| 9435 // Names that are in this library's dictionary and are unmangled | 9488 // Names that are in this library's dictionary and are unmangled |
| 9436 // are not cached. This reduces the size of the the cache. | 9489 // are not cached. This reduces the size of the the cache. |
| 9437 return obj.raw(); | 9490 return obj.raw(); |
| 9438 } | 9491 } |
| 9492 | |
| 9439 String& accessor_name = String::Handle(Field::LookupGetterSymbol(name)); | 9493 String& accessor_name = String::Handle(Field::LookupGetterSymbol(name)); |
| 9440 if (!accessor_name.IsNull()) { | 9494 if (!accessor_name.IsNull()) { |
| 9441 obj = LookupLocalObject(accessor_name); | 9495 obj = LookupLocalObject(accessor_name); |
| 9442 } | 9496 } |
| 9443 if (obj.IsNull()) { | 9497 if (obj.IsNull()) { |
| 9444 accessor_name = Field::LookupSetterSymbol(name); | 9498 accessor_name = Field::LookupSetterSymbol(name); |
| 9445 if (!accessor_name.IsNull()) { | 9499 if (!accessor_name.IsNull()) { |
| 9446 obj = LookupLocalObject(accessor_name); | 9500 obj = LookupLocalObject(accessor_name); |
| 9447 } | 9501 } |
| 9448 if (obj.IsNull() && !ShouldBePrivate(name)) { | 9502 if (obj.IsNull() && !ShouldBePrivate(name)) { |
| 9449 obj = LookupImportedObject(name); | 9503 obj = LookupImportedObject(name); |
| 9450 } | 9504 } |
| 9451 } | 9505 } |
| 9506 | |
| 9452 AddToResolvedNamesCache(name, obj); | 9507 AddToResolvedNamesCache(name, obj); |
| 9453 return obj.raw(); | 9508 return obj.raw(); |
| 9454 } | 9509 } |
| 9455 | 9510 |
| 9456 | 9511 |
| 9457 class StringEqualsTraits { | 9512 class StringEqualsTraits { |
| 9458 public: | 9513 public: |
| 9459 static bool IsMatch(const Object& a, const Object& b) { | 9514 static bool IsMatch(const Object& a, const Object& b) { |
| 9460 return String::Cast(a).Equals(String::Cast(b)); | 9515 return String::Cast(a).Equals(String::Cast(b)); |
| 9461 } | 9516 } |
| (...skipping 12419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 21881 return UserTag::null(); | 21936 return UserTag::null(); |
| 21882 } | 21937 } |
| 21883 | 21938 |
| 21884 | 21939 |
| 21885 const char* UserTag::ToCString() const { | 21940 const char* UserTag::ToCString() const { |
| 21886 const String& tag_label = String::Handle(label()); | 21941 const String& tag_label = String::Handle(label()); |
| 21887 return tag_label.ToCString(); | 21942 return tag_label.ToCString(); |
| 21888 } | 21943 } |
| 21889 | 21944 |
| 21890 } // namespace dart | 21945 } // namespace dart |
| OLD | NEW |