fune/parser/html/nsHtml5AtomTable.cpp
Chris Peterson 2afd829d0f Bug 1469769 - Part 6: Replace non-failing NS_NOTREACHED with MOZ_ASSERT_UNREACHABLE. r=froydnj
This patch is an automatic replacement of s/NS_NOTREACHED/MOZ_ASSERT_UNREACHABLE/. Reindenting long lines and whitespace fixups follow in patch 6b.

MozReview-Commit-ID: 5UQVHElSpCr

--HG--
extra : rebase_source : 4c1b2fc32b269342f07639266b64941e2270e9c4
extra : source : 907543f6eae716f23a6de52b1ffb1c82908d158a
2018-06-17 22:43:11 -07:00

63 lines
1.5 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsHtml5AtomTable.h"
#include "nsThreadUtils.h"
nsHtml5AtomEntry::nsHtml5AtomEntry(KeyTypePointer aStr)
: nsStringHashKey(aStr)
, mAtom(nsDynamicAtom::Create(*aStr))
{
}
nsHtml5AtomEntry::nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther)
: nsStringHashKey(aOther)
, mAtom(nullptr)
{
MOZ_ASSERT_UNREACHABLE("nsHtml5AtomTable is broken; tried to copy an entry");
}
nsHtml5AtomEntry::~nsHtml5AtomEntry()
{
nsDynamicAtom::Destroy(mAtom);
}
nsHtml5AtomTable::nsHtml5AtomTable()
: mRecentlyUsedParserAtoms{}
{
#ifdef DEBUG
mPermittedLookupEventTarget = mozilla::GetCurrentThreadSerialEventTarget();
#endif
}
nsHtml5AtomTable::~nsHtml5AtomTable() {}
nsAtom*
nsHtml5AtomTable::GetAtom(const nsAString& aKey)
{
#ifdef DEBUG
{
MOZ_ASSERT(mPermittedLookupEventTarget->IsOnCurrentThread());
}
#endif
uint32_t index = mozilla::HashString(aKey) % RECENTLY_USED_PARSER_ATOMS_SIZE;
nsAtom* cachedAtom = mRecentlyUsedParserAtoms[index];
if (cachedAtom && cachedAtom->Equals(aKey)) {
return cachedAtom;
}
nsStaticAtom* atom = NS_GetStaticAtom(aKey);
if (atom) {
mRecentlyUsedParserAtoms[index] = atom;
return atom;
}
nsHtml5AtomEntry* entry = mTable.PutEntry(aKey);
if (!entry) {
return nullptr;
}
mRecentlyUsedParserAtoms[index] = entry->GetAtom();
return entry->GetAtom();
}