/src/mozilla-central/parser/html/nsHtml5AtomTable.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | nsHtml5AtomEntry::nsHtml5AtomEntry(KeyTypePointer aStr) |
9 | | : nsStringHashKey(aStr) |
10 | | , mAtom(nsDynamicAtom::Create(*aStr)) |
11 | 0 | { |
12 | 0 | } |
13 | | |
14 | | nsHtml5AtomEntry::nsHtml5AtomEntry(nsHtml5AtomEntry&& aOther) |
15 | | : nsStringHashKey(std::move(aOther)) |
16 | | , mAtom(nullptr) |
17 | 0 | { |
18 | 0 | MOZ_ASSERT_UNREACHABLE("nsHtml5AtomTable is broken; tried to copy an entry"); |
19 | 0 | } |
20 | | |
21 | | nsHtml5AtomEntry::~nsHtml5AtomEntry() |
22 | 0 | { |
23 | 0 | nsDynamicAtom::Destroy(mAtom); |
24 | 0 | } |
25 | | |
26 | | nsHtml5AtomTable::nsHtml5AtomTable() |
27 | | : mRecentlyUsedParserAtoms{} |
28 | 0 | { |
29 | | #ifdef DEBUG |
30 | | mPermittedLookupEventTarget = mozilla::GetCurrentThreadSerialEventTarget(); |
31 | | #endif |
32 | | } |
33 | | |
34 | 0 | nsHtml5AtomTable::~nsHtml5AtomTable() {} |
35 | | |
36 | | nsAtom* |
37 | | nsHtml5AtomTable::GetAtom(const nsAString& aKey) |
38 | 0 | { |
39 | | #ifdef DEBUG |
40 | | { |
41 | | MOZ_ASSERT(mPermittedLookupEventTarget->IsOnCurrentThread()); |
42 | | } |
43 | | #endif |
44 | |
|
45 | 0 | uint32_t index = mozilla::HashString(aKey) % RECENTLY_USED_PARSER_ATOMS_SIZE; |
46 | 0 | nsAtom* cachedAtom = mRecentlyUsedParserAtoms[index]; |
47 | 0 | if (cachedAtom && cachedAtom->Equals(aKey)) { |
48 | 0 | return cachedAtom; |
49 | 0 | } |
50 | 0 | |
51 | 0 | nsStaticAtom* atom = NS_GetStaticAtom(aKey); |
52 | 0 | if (atom) { |
53 | 0 | mRecentlyUsedParserAtoms[index] = atom; |
54 | 0 | return atom; |
55 | 0 | } |
56 | 0 | nsHtml5AtomEntry* entry = mTable.PutEntry(aKey); |
57 | 0 | if (!entry) { |
58 | 0 | return nullptr; |
59 | 0 | } |
60 | 0 | |
61 | 0 | mRecentlyUsedParserAtoms[index] = entry->GetAtom(); |
62 | 0 | return entry->GetAtom(); |
63 | 0 | } |