michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsHtml5AtomTable.h" michael@0: #include "nsHtml5Atom.h" michael@0: #include "nsThreadUtils.h" michael@0: michael@0: nsHtml5AtomEntry::nsHtml5AtomEntry(KeyTypePointer aStr) michael@0: : nsStringHashKey(aStr) michael@0: , mAtom(new nsHtml5Atom(*aStr)) michael@0: { michael@0: } michael@0: michael@0: nsHtml5AtomEntry::nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther) michael@0: : nsStringHashKey(aOther) michael@0: , mAtom(nullptr) michael@0: { michael@0: NS_NOTREACHED("nsHtml5AtomTable is broken and tried to copy an entry"); michael@0: } michael@0: michael@0: nsHtml5AtomEntry::~nsHtml5AtomEntry() michael@0: { michael@0: } michael@0: michael@0: nsHtml5AtomTable::nsHtml5AtomTable() michael@0: { michael@0: #ifdef DEBUG michael@0: NS_GetMainThread(getter_AddRefs(mPermittedLookupThread)); michael@0: #endif michael@0: } michael@0: michael@0: nsHtml5AtomTable::~nsHtml5AtomTable() michael@0: { michael@0: } michael@0: michael@0: nsIAtom* michael@0: nsHtml5AtomTable::GetAtom(const nsAString& aKey) michael@0: { michael@0: #ifdef DEBUG michael@0: { michael@0: nsCOMPtr currentThread; michael@0: NS_GetCurrentThread(getter_AddRefs(currentThread)); michael@0: NS_ASSERTION(mPermittedLookupThread == currentThread, "Wrong thread!"); michael@0: } michael@0: #endif michael@0: nsIAtom* atom = NS_GetStaticAtom(aKey); michael@0: if (atom) { michael@0: return atom; michael@0: } michael@0: nsHtml5AtomEntry* entry = mTable.PutEntry(aKey); michael@0: if (!entry) { michael@0: return nullptr; michael@0: } michael@0: return entry->GetAtom(); michael@0: }