|
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 "nsHtml5Atom.h" |
|
7 #include "nsThreadUtils.h" |
|
8 |
|
9 nsHtml5AtomEntry::nsHtml5AtomEntry(KeyTypePointer aStr) |
|
10 : nsStringHashKey(aStr) |
|
11 , mAtom(new nsHtml5Atom(*aStr)) |
|
12 { |
|
13 } |
|
14 |
|
15 nsHtml5AtomEntry::nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther) |
|
16 : nsStringHashKey(aOther) |
|
17 , mAtom(nullptr) |
|
18 { |
|
19 NS_NOTREACHED("nsHtml5AtomTable is broken and tried to copy an entry"); |
|
20 } |
|
21 |
|
22 nsHtml5AtomEntry::~nsHtml5AtomEntry() |
|
23 { |
|
24 } |
|
25 |
|
26 nsHtml5AtomTable::nsHtml5AtomTable() |
|
27 { |
|
28 #ifdef DEBUG |
|
29 NS_GetMainThread(getter_AddRefs(mPermittedLookupThread)); |
|
30 #endif |
|
31 } |
|
32 |
|
33 nsHtml5AtomTable::~nsHtml5AtomTable() |
|
34 { |
|
35 } |
|
36 |
|
37 nsIAtom* |
|
38 nsHtml5AtomTable::GetAtom(const nsAString& aKey) |
|
39 { |
|
40 #ifdef DEBUG |
|
41 { |
|
42 nsCOMPtr<nsIThread> currentThread; |
|
43 NS_GetCurrentThread(getter_AddRefs(currentThread)); |
|
44 NS_ASSERTION(mPermittedLookupThread == currentThread, "Wrong thread!"); |
|
45 } |
|
46 #endif |
|
47 nsIAtom* atom = NS_GetStaticAtom(aKey); |
|
48 if (atom) { |
|
49 return atom; |
|
50 } |
|
51 nsHtml5AtomEntry* entry = mTable.PutEntry(aKey); |
|
52 if (!entry) { |
|
53 return nullptr; |
|
54 } |
|
55 return entry->GetAtom(); |
|
56 } |