Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index ba54f54937c5c458ba0d48dfd9aa4307dc7fda9b..a4a8a64a02d0fa855a38d7975c330e71dafd4a7a 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -9658,7 +9658,7 @@ RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { |
| while (!entry.IsNull()) { |
| entry_name = entry.DictionaryName(); |
| ASSERT(!entry_name.IsNull()); |
| - if (entry_name.Equals(name)) { |
| + if (entry_name.Equals(name)) { |
| return entry.raw(); |
| } |
| *index = (*index + 1) % dict_size; |
| @@ -9680,6 +9680,52 @@ void Library::ReplaceObject(const Object& obj, const String& name) const { |
| } |
| +bool Library::RemoveObject(const Object& obj, const String& name) const { |
| + Object& entry = Object::Handle(); |
| + |
| + intptr_t index; |
| + entry = LookupEntry(name, &index); |
| + if (entry.raw() != obj.raw()) { |
| + return false; |
| + } |
| + |
| + const Array& dict = Array::Handle(dictionary()); |
| + dict.SetAt(index, Object::null_object()); |
| + intptr_t dict_size = dict.Length() - 1; |
| + |
| + // Fix any downstream collisions. |
| + String& key = String::Handle(); |
| + for (;;) { |
| + index = (index + 1) % dict_size; |
| + entry = dict.At(index); |
| + |
| + if (entry.IsNull()) break; |
| + |
| + key = entry.DictionaryName(); |
| + intptr_t new_index = key.Hash() % dict_size; |
| + while ((dict.At(new_index) != entry.raw()) && |
| + (dict.At(new_index) != Object::null())) { |
| + new_index = (new_index + 1) % dict_size; |
| + } |
| + |
| + if (index != new_index) { |
| + ASSERT(dict.At(new_index) == Object::null()); |
| + dict.SetAt(new_index, entry); |
| + dict.SetAt(index, Object::null_object()); |
| + } |
| + } |
| + |
| + // Update used count. |
| + intptr_t used_elements = Smi::Value(Smi::RawCast(dict.At(dict_size))) - 1; |
| + dict.SetAt(dict_size, Smi::Handle(Smi::New(used_elements))); |
| + |
| + StorePointer(&raw_ptr()->resolved_names_, |
| + 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
|
| + |
| + return true; |
| +} |
| + |
| + |
| void Library::AddClass(const Class& cls) const { |
| const String& class_name = String::Handle(cls.Name()); |
| AddObject(cls, class_name); |