nsHtml5AtomTable.cpp (989B)
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/. */ 4 5 #include "nsHtml5AtomTable.h" 6 #include "nsThreadUtils.h" 7 8 nsHtml5AtomTable::nsHtml5AtomTable() : mRecentlyUsedParserAtoms{} { 9 #ifdef DEBUG 10 mPermittedLookupEventTarget = mozilla::GetCurrentSerialEventTarget(); 11 #endif 12 } 13 14 nsHtml5AtomTable::~nsHtml5AtomTable() = default; 15 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; 23 } 24 } 25 26 RefPtr<nsAtom> atom = NS_Atomize(aKey, hash); 27 nsAtom* ret = atom.get(); 28 mRecentlyUsedParserAtoms[index] = std::move(atom); 29 return ret; 30 }