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

Unified Diff: runtime/vm/object.cc

Issue 1643023003: Precompilation: when removing top-level fields and functions, also remove them from the library dic… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
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);
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/precompiler.h » ('j') | runtime/vm/precompiler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698