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) { 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); RefPtr<nsAtom> id = NS_Atomize(aID);
return new nsContentList(mDocument, DocAllResultMatch, nullptr, nullptr, return new nsContentList(mDocument, DocAllResultMatch, nullptr,
true, id); nullptr, true, id);
})
.get();
}); });
} }

View File

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