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 9640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9651 dict ^= dictionary(); | 9651 dict ^= dictionary(); |
| 9652 intptr_t dict_size = dict.Length() - 1; | 9652 intptr_t dict_size = dict.Length() - 1; |
| 9653 *index = name.Hash() % dict_size; | 9653 *index = name.Hash() % dict_size; |
| 9654 Object& entry = thread->ObjectHandle(); | 9654 Object& entry = thread->ObjectHandle(); |
| 9655 String& entry_name = thread->StringHandle(); | 9655 String& entry_name = thread->StringHandle(); |
| 9656 entry = dict.At(*index); | 9656 entry = dict.At(*index); |
| 9657 // Search the entry in the hash set. | 9657 // Search the entry in the hash set. |
| 9658 while (!entry.IsNull()) { | 9658 while (!entry.IsNull()) { |
| 9659 entry_name = entry.DictionaryName(); | 9659 entry_name = entry.DictionaryName(); |
| 9660 ASSERT(!entry_name.IsNull()); | 9660 ASSERT(!entry_name.IsNull()); |
| 9661 if (entry_name.Equals(name)) { | 9661 if (entry_name.Equals(name)) { |
| 9662 return entry.raw(); | 9662 return entry.raw(); |
| 9663 } | 9663 } |
| 9664 *index = (*index + 1) % dict_size; | 9664 *index = (*index + 1) % dict_size; |
| 9665 entry = dict.At(*index); | 9665 entry = dict.At(*index); |
| 9666 } | 9666 } |
| 9667 return Object::null(); | 9667 return Object::null(); |
| 9668 } | 9668 } |
| 9669 | 9669 |
| 9670 | 9670 |
| 9671 void Library::ReplaceObject(const Object& obj, const String& name) const { | 9671 void Library::ReplaceObject(const Object& obj, const String& name) const { |
| 9672 ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField()); | 9672 ASSERT(obj.IsClass() || obj.IsFunction() || obj.IsField()); |
| 9673 ASSERT(LookupLocalObject(name) != Object::null()); | 9673 ASSERT(LookupLocalObject(name) != Object::null()); |
| 9674 | 9674 |
| 9675 intptr_t index; | 9675 intptr_t index; |
| 9676 LookupEntry(name, &index); | 9676 LookupEntry(name, &index); |
| 9677 // The value is guaranteed to be found. | 9677 // The value is guaranteed to be found. |
| 9678 const Array& dict = Array::Handle(dictionary()); | 9678 const Array& dict = Array::Handle(dictionary()); |
| 9679 dict.SetAt(index, obj); | 9679 dict.SetAt(index, obj); |
| 9680 } | 9680 } |
| 9681 | 9681 |
| 9682 | 9682 |
| 9683 bool Library::RemoveObject(const Object& obj, const String& name) const { | |
| 9684 Object& entry = Object::Handle(); | |
| 9685 | |
| 9686 intptr_t index; | |
| 9687 entry = LookupEntry(name, &index); | |
| 9688 if (entry.raw() != obj.raw()) { | |
| 9689 return false; | |
| 9690 } | |
| 9691 | |
| 9692 const Array& dict = Array::Handle(dictionary()); | |
| 9693 dict.SetAt(index, Object::null_object()); | |
| 9694 intptr_t dict_size = dict.Length() - 1; | |
| 9695 | |
| 9696 // Fix any downstream collisions. | |
| 9697 String& key = String::Handle(); | |
| 9698 for (;;) { | |
| 9699 index = (index + 1) % dict_size; | |
| 9700 entry = dict.At(index); | |
| 9701 | |
| 9702 if (entry.IsNull()) break; | |
| 9703 | |
| 9704 key = entry.DictionaryName(); | |
| 9705 intptr_t new_index = key.Hash() % dict_size; | |
| 9706 while ((dict.At(new_index) != entry.raw()) && | |
| 9707 (dict.At(new_index) != Object::null())) { | |
| 9708 new_index = (new_index + 1) % dict_size; | |
| 9709 } | |
| 9710 | |
| 9711 if (index != new_index) { | |
| 9712 ASSERT(dict.At(new_index) == Object::null()); | |
| 9713 dict.SetAt(new_index, entry); | |
| 9714 dict.SetAt(index, Object::null_object()); | |
| 9715 } | |
| 9716 } | |
| 9717 | |
| 9718 // Update used count. | |
| 9719 intptr_t used_elements = Smi::Value(Smi::RawCast(dict.At(dict_size))) - 1; | |
| 9720 dict.SetAt(dict_size, Smi::Handle(Smi::New(used_elements))); | |
| 9721 | |
| 9722 StorePointer(&raw_ptr()->resolved_names_, | |
| 9723 HashTables::New<ResolvedNamesMap>(0)); | |
|
Florian Schneider
2016/02/02 21:30:19
Can you use InvalidateResolvedNamesCache? Or use a
rmacnak
2016/02/03 01:43:39
Switched to InvalidateResolvedNamesCache
| |
| 9724 | |
| 9725 return true; | |
| 9726 } | |
| 9727 | |
| 9728 | |
| 9683 void Library::AddClass(const Class& cls) const { | 9729 void Library::AddClass(const Class& cls) const { |
| 9684 const String& class_name = String::Handle(cls.Name()); | 9730 const String& class_name = String::Handle(cls.Name()); |
| 9685 AddObject(cls, class_name); | 9731 AddObject(cls, class_name); |
| 9686 // Link class to this library. | 9732 // Link class to this library. |
| 9687 cls.set_library(*this); | 9733 cls.set_library(*this); |
| 9688 InvalidateResolvedName(class_name); | 9734 InvalidateResolvedName(class_name); |
| 9689 } | 9735 } |
| 9690 | 9736 |
| 9691 static void AddScriptIfUnique(const GrowableObjectArray& scripts, | 9737 static void AddScriptIfUnique(const GrowableObjectArray& scripts, |
| 9692 const Script& candidate) { | 9738 const Script& candidate) { |
| (...skipping 13146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22839 return tag_label.ToCString(); | 22885 return tag_label.ToCString(); |
| 22840 } | 22886 } |
| 22841 | 22887 |
| 22842 | 22888 |
| 22843 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 22889 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 22844 Instance::PrintJSONImpl(stream, ref); | 22890 Instance::PrintJSONImpl(stream, ref); |
| 22845 } | 22891 } |
| 22846 | 22892 |
| 22847 | 22893 |
| 22848 } // namespace dart | 22894 } // namespace dart |
| OLD | NEW |