Bug 1861243 [wpt PR 42755] - Add long timeout to pagereveal WPT, a=testonly
[gecko.git] / parser / html / nsHtml5AtomTable.cpp
blobb6db18409850cb1102f567c2867ae86d664d99ed
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() = default;
16 nsAtom* nsHtml5AtomTable::GetAtom(const nsAString& aKey) {
17 MOZ_ASSERT(mPermittedLookupEventTarget->IsOnCurrentThread());
18 uint32_t hash = mozilla::HashString(aKey);
19 uint32_t index = hash % RECENTLY_USED_PARSER_ATOMS_SIZE;
20 if (nsAtom* atom = mRecentlyUsedParserAtoms[index]) {
21 if (atom->hash() == hash && atom->Equals(aKey)) {
22 return atom;
26 RefPtr<nsAtom> atom = NS_Atomize(aKey, hash);
27 nsAtom* ret = atom.get();
28 mRecentlyUsedParserAtoms[index] = std::move(atom);
29 return ret;