Bug 1688833 - Migrate LookupForAdd to WithEntryHandle in dom/html. r=mattwoodrow

Differential Revision: https://phabricator.services.mozilla.com/D104226
This commit is contained in:
Simon Giesecke
2021-02-09 18:19:43 +00:00
parent 01c31668a0
commit 525b2b7549
2 changed files with 83 additions and 79 deletions

View File

@@ -104,10 +104,14 @@ static bool DocAllResultMatch(Element* aElement, int32_t aNamespaceID,
}
nsContentList* HTMLAllCollection::GetDocumentAllList(const nsAString& aID) {
return mNamedMap.LookupForAdd(aID).OrInsert([this, &aID]() {
return mNamedMap.WithEntryHandle(aID, [&](auto&& entry) {
return entry
.OrInsertWith([this, &aID] {
RefPtr<nsAtom> id = NS_Atomize(aID);
return new nsContentList(mDocument, DocAllResultMatch, nullptr, nullptr,
true, id);
return new nsContentList(mDocument, DocAllResultMatch, nullptr,
nullptr, true, id);
})
.get();
});
}

View File

@@ -2169,12 +2169,10 @@ HTMLFormElement::WalkRadioGroup(const nsAString& aName,
void HTMLFormElement::AddToRadioGroup(const nsAString& aName,
HTMLInputElement* aRadio) {
if (aRadio->IsRequired()) {
auto entry = mRequiredRadioButtonCounts.LookupForAdd(aName);
if (!entry) {
entry.OrInsert([]() { return 1; });
} else {
++entry.Data();
}
mRequiredRadioButtonCounts.WithEntryHandle(aName, [](auto&& entry) {
uint32_t& value = entry.OrInsert(0);
++value;
});
}
}
@@ -2276,10 +2274,10 @@ struct RadioNodeListAdaptor {
nsresult HTMLFormElement::AddElementToTableInternal(
nsInterfaceHashtable<nsStringHashKey, nsISupports>& aTable,
nsIContent* aChild, const nsAString& aName) {
auto entry = aTable.LookupForAdd(aName);
return aTable.WithEntryHandle(aName, [&](auto&& entry) {
if (!entry) {
// No entry found, add the element
entry.OrInsert([&aChild]() { return aChild; });
entry.Insert(aChild);
++mExpandoAndGeneration.generation;
} else {
// Found something in the hash, check its type
@@ -2298,11 +2296,11 @@ nsresult HTMLFormElement::AddElementToTableInternal(
// the list in the hash
RadioNodeList* list = new RadioNodeList(this);
// If an element has a @form, we can assume it *might* be able to not have
// a parent and still be in the form.
// If an element has a @form, we can assume it *might* be able to not
// have a parent and still be in the form.
NS_ASSERTION(
(content->IsElement() &&
content->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::form)) ||
(content->IsElement() && content->AsElement()->HasAttr(
kNameSpaceID_None, nsGkAtoms::form)) ||
content->GetParent(),
"Item in list without parent");
@@ -2321,7 +2319,8 @@ nsresult HTMLFormElement::AddElementToTableInternal(
MOZ_ASSERT(nsCOMPtr<RadioNodeList>(do_QueryInterface(entry.Data())));
auto* list = static_cast<RadioNodeList*>(entry.Data().get());
NS_ASSERTION(list->Length() > 1,
NS_ASSERTION(
list->Length() > 1,
"List should have been converted back to a single element");
// Fast-path appends; this check is ok even if the child is
@@ -2351,6 +2350,7 @@ nsresult HTMLFormElement::AddElementToTableInternal(
}
return NS_OK;
});
}
nsresult HTMLFormElement::AddImageElement(HTMLImageElement* aChild) {