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
{} {
10 mPermittedLookupEventTarget
= mozilla::GetCurrentSerialEventTarget();
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
)) {
26 RefPtr
<nsAtom
> atom
= NS_Atomize(aKey
, hash
);
27 nsAtom
* ret
= atom
.get();
28 mRecentlyUsedParserAtoms
[index
] = std::move(atom
);