Bug 1845715 - Check for failure when getting RegExp match result template r=iain
[gecko.git] / parser / html / nsHtml5AtomTable.cpp
blob06bad88bf477392ba3c2b462a110ff7614ef9a3d
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "nsHtml5AtomTable.h"
6 #include "nsThreadUtils.h"
8 nsHtml5AtomTable::nsHtml5AtomTable() : mRecentlyUsedParserAtoms{} {
9 #ifdef DEBUG
10 mPermittedLookupEventTarget = mozilla::GetCurrentSerialEventTarget();
11 #endif
14 nsHtml5AtomTable::~nsHtml5AtomTable() {}
16 nsAtom* nsHtml5AtomTable::GetAtom(const nsAString& aKey) {
17 #ifdef DEBUG
18 MOZ_ASSERT(mPermittedLookupEventTarget->IsOnCurrentThread());
19 #endif
21 uint32_t index = mozilla::HashString(aKey) % RECENTLY_USED_PARSER_ATOMS_SIZE;
22 if (nsAtom* atom = mRecentlyUsedParserAtoms[index]) {
23 if (atom->Equals(aKey)) {
24 return atom;
28 RefPtr<nsAtom> atom = NS_Atomize(aKey);
29 nsAtom* ret = atom.get();
30 mRecentlyUsedParserAtoms[index] = std::move(atom);
31 return ret;