Bug 912567 - Split HashMap/HashSet::rekey() into rekey() and rekeyIfMoved() r=terrence

This commit is contained in:
Jon Coppeard 2013-09-24 10:03:32 +01:00
parent a78e1fb9ba
commit a9d324a316
5 changed files with 25 additions and 15 deletions

View File

@ -105,7 +105,7 @@ ObjectIdCache::keyMarkCallback(JSTracer *trc, void *k, void *d) {
ObjectIdCache* self = static_cast<ObjectIdCache*>(d);
JSObject *prior = key;
JS_CallObjectTracer(trc, &key, "ObjectIdCache::table_ key");
self->table_.rekey(prior, key);
self->table_.rekeyIfMoved(prior, key);
}
void

View File

@ -250,12 +250,17 @@ class HashMap
remove(p);
}
// Infallibly rekey one entry, if necessary.
// Requires template parameters Key and HashPolicy::Lookup to be the same type.
void rekeyIfMoved(const Key &old_key, const Key &new_key) {
if (old_key != new_key)
rekeyAs(old_key, new_key, new_key);
}
// Infallibly rekey one entry, if present.
void rekey(const Lookup &old_key, const Key &new_key) {
if (old_key != new_key) {
if (Ptr p = lookup(old_key))
impl.rekeyAndMaybeRehash(p, new_key, new_key);
}
void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const Key &new_key) {
if (Ptr p = lookup(old_lookup))
impl.rekeyAndMaybeRehash(p, new_lookup, new_key);
}
// HashMap is movable
@ -450,11 +455,16 @@ class HashSet
}
// Infallibly rekey one entry, if present.
void rekey(const Lookup &old_key, const T &new_key) {
if (old_key != new_key) {
if (Ptr p = lookup(old_key))
impl.rekeyAndMaybeRehash(p, new_key, new_key);
}
// Requires template parameters T and HashPolicy::Lookup to be the same type.
void rekeyIfMoved(const Lookup &old_value, const T &new_value) {
if (old_value != new_value)
rekeyAs(old_value, new_value, new_value);
}
// Infallibly rekey one entry, if present.
void rekeyAs(const Lookup &old_lookup, const Lookup &new_lookup, const T &new_value) {
if (Ptr p = lookup(old_lookup))
impl.rekeyAndMaybeRehash(p, new_lookup, new_value);
}
// HashSet is movable

View File

@ -4744,7 +4744,7 @@ PostBarrierCallback(JSTracer *trc, void *k, void *d)
FieldInfoHash *table = static_cast<FieldInfoHash*>(d);
JSString *key = prior;
JS_CallStringTracer(trc, &key, "CType fieldName");
table->rekey(JS_ASSERT_STRING_IS_FLAT(prior), JS_ASSERT_STRING_IS_FLAT(key));
table->rekeyIfMoved(JS_ASSERT_STRING_IS_FLAT(prior), JS_ASSERT_STRING_IS_FLAT(key));
}
bool

View File

@ -59,7 +59,7 @@ class HashKeyRef : public BufferableRef
return;
JS_SET_TRACING_LOCATION(trc, (void*)&*p);
Mark(trc, &key, "HashKeyRef");
map->rekey(prior, key);
map->rekeyIfMoved(prior, key);
}
};

View File

@ -90,7 +90,7 @@ private:
JSObject2WrappedJSMap* self = static_cast<JSObject2WrappedJSMap*>(d);
JSObject *prior = key;
JS_CallObjectTracer(trc, &key, "XPCJSRuntime::mWrappedJSMap key");
self->mTable.rekey(prior, key);
self->mTable.rekeyIfMoved(prior, key);
}
Map mTable;
@ -699,7 +699,7 @@ private:
JSObject2JSObjectMap *self = static_cast<JSObject2JSObjectMap *>(d);
JSObject *prior = key;
JS_CallObjectTracer(trc, &key, "XPCWrappedNativeScope::mWaiverWrapperMap key");
self->mTable.rekey(prior, key);
self->mTable.rekeyIfMoved(prior, key);
}
Map mTable;