Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsHtml5AtomTable.h" |
michael@0 | 6 | #include "nsHtml5Atom.h" |
michael@0 | 7 | #include "nsThreadUtils.h" |
michael@0 | 8 | |
michael@0 | 9 | nsHtml5AtomEntry::nsHtml5AtomEntry(KeyTypePointer aStr) |
michael@0 | 10 | : nsStringHashKey(aStr) |
michael@0 | 11 | , mAtom(new nsHtml5Atom(*aStr)) |
michael@0 | 12 | { |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | nsHtml5AtomEntry::nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther) |
michael@0 | 16 | : nsStringHashKey(aOther) |
michael@0 | 17 | , mAtom(nullptr) |
michael@0 | 18 | { |
michael@0 | 19 | NS_NOTREACHED("nsHtml5AtomTable is broken and tried to copy an entry"); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | nsHtml5AtomEntry::~nsHtml5AtomEntry() |
michael@0 | 23 | { |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | nsHtml5AtomTable::nsHtml5AtomTable() |
michael@0 | 27 | { |
michael@0 | 28 | #ifdef DEBUG |
michael@0 | 29 | NS_GetMainThread(getter_AddRefs(mPermittedLookupThread)); |
michael@0 | 30 | #endif |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | nsHtml5AtomTable::~nsHtml5AtomTable() |
michael@0 | 34 | { |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | nsIAtom* |
michael@0 | 38 | nsHtml5AtomTable::GetAtom(const nsAString& aKey) |
michael@0 | 39 | { |
michael@0 | 40 | #ifdef DEBUG |
michael@0 | 41 | { |
michael@0 | 42 | nsCOMPtr<nsIThread> currentThread; |
michael@0 | 43 | NS_GetCurrentThread(getter_AddRefs(currentThread)); |
michael@0 | 44 | NS_ASSERTION(mPermittedLookupThread == currentThread, "Wrong thread!"); |
michael@0 | 45 | } |
michael@0 | 46 | #endif |
michael@0 | 47 | nsIAtom* atom = NS_GetStaticAtom(aKey); |
michael@0 | 48 | if (atom) { |
michael@0 | 49 | return atom; |
michael@0 | 50 | } |
michael@0 | 51 | nsHtml5AtomEntry* entry = mTable.PutEntry(aKey); |
michael@0 | 52 | if (!entry) { |
michael@0 | 53 | return nullptr; |
michael@0 | 54 | } |
michael@0 | 55 | return entry->GetAtom(); |
michael@0 | 56 | } |