1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/parser/html/nsHtml5AtomTable.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#include "nsHtml5AtomTable.h" 1.9 +#include "nsHtml5Atom.h" 1.10 +#include "nsThreadUtils.h" 1.11 + 1.12 +nsHtml5AtomEntry::nsHtml5AtomEntry(KeyTypePointer aStr) 1.13 + : nsStringHashKey(aStr) 1.14 + , mAtom(new nsHtml5Atom(*aStr)) 1.15 +{ 1.16 +} 1.17 + 1.18 +nsHtml5AtomEntry::nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther) 1.19 + : nsStringHashKey(aOther) 1.20 + , mAtom(nullptr) 1.21 +{ 1.22 + NS_NOTREACHED("nsHtml5AtomTable is broken and tried to copy an entry"); 1.23 +} 1.24 + 1.25 +nsHtml5AtomEntry::~nsHtml5AtomEntry() 1.26 +{ 1.27 +} 1.28 + 1.29 +nsHtml5AtomTable::nsHtml5AtomTable() 1.30 +{ 1.31 +#ifdef DEBUG 1.32 + NS_GetMainThread(getter_AddRefs(mPermittedLookupThread)); 1.33 +#endif 1.34 +} 1.35 + 1.36 +nsHtml5AtomTable::~nsHtml5AtomTable() 1.37 +{ 1.38 +} 1.39 + 1.40 +nsIAtom* 1.41 +nsHtml5AtomTable::GetAtom(const nsAString& aKey) 1.42 +{ 1.43 +#ifdef DEBUG 1.44 + { 1.45 + nsCOMPtr<nsIThread> currentThread; 1.46 + NS_GetCurrentThread(getter_AddRefs(currentThread)); 1.47 + NS_ASSERTION(mPermittedLookupThread == currentThread, "Wrong thread!"); 1.48 + } 1.49 +#endif 1.50 + nsIAtom* atom = NS_GetStaticAtom(aKey); 1.51 + if (atom) { 1.52 + return atom; 1.53 + } 1.54 + nsHtml5AtomEntry* entry = mTable.PutEntry(aKey); 1.55 + if (!entry) { 1.56 + return nullptr; 1.57 + } 1.58 + return entry->GetAtom(); 1.59 +}