diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:35:29 +0000 |
commit | 59203c63bb777a3bacec32fb8830fba33540e809 (patch) | |
tree | 58298e711c0ff0575818c30485b44a2f21bf28a0 /dom/base/HighlightRegistry.cpp | |
parent | Adding upstream version 126.0.1. (diff) | |
download | firefox-59203c63bb777a3bacec32fb8830fba33540e809.tar.xz firefox-59203c63bb777a3bacec32fb8830fba33540e809.zip |
Adding upstream version 127.0.upstream/127.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/HighlightRegistry.cpp')
-rw-r--r-- | dom/base/HighlightRegistry.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/dom/base/HighlightRegistry.cpp b/dom/base/HighlightRegistry.cpp index 035aadb78a..755977286f 100644 --- a/dom/base/HighlightRegistry.cpp +++ b/dom/base/HighlightRegistry.cpp @@ -133,18 +133,28 @@ void HighlightRegistry::AddHighlightSelectionsToFrameSelection() { void HighlightRegistry::Set(const nsAString& aKey, Highlight& aValue, ErrorResult& aRv) { + // manually check if the highlight `aKey` is already registered to be able to + // provide a fast path later that avoids calling `std::find_if()`. + const bool highlightAlreadyPresent = + HighlightRegistry_Binding::MaplikeHelpers::Has(this, aKey, aRv); + if (aRv.Failed()) { + return; + } HighlightRegistry_Binding::MaplikeHelpers::Set(this, aKey, aValue, aRv); if (aRv.Failed()) { return; } RefPtr<nsFrameSelection> frameSelection = GetFrameSelection(); RefPtr<nsAtom> highlightNameAtom = NS_AtomizeMainThread(aKey); - auto foundIter = - std::find_if(mHighlightsOrdered.begin(), mHighlightsOrdered.end(), - [&highlightNameAtom](auto const& aElm) { - return aElm.first() == highlightNameAtom; - }); - if (foundIter != mHighlightsOrdered.end()) { + if (highlightAlreadyPresent) { + // If the highlight named `aKey` was present before, replace its value. + auto foundIter = + std::find_if(mHighlightsOrdered.begin(), mHighlightsOrdered.end(), + [&highlightNameAtom](auto const& aElm) { + return aElm.first() == highlightNameAtom; + }); + MOZ_ASSERT(foundIter != mHighlightsOrdered.end(), + "webIDL maplike and DOM mirror are not in sync"); foundIter->second()->RemoveFromHighlightRegistry(*this, *highlightNameAtom); if (frameSelection) { frameSelection->RemoveHighlightSelection(highlightNameAtom); |