Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
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/. */
5 #ifndef nsHtml5AtomTable_h
6 #define nsHtml5AtomTable_h
8 #include "nsHashKeys.h"
9 #include "nsTHashtable.h"
10 #include "nsAutoPtr.h"
11 #include "nsIAtom.h"
12 #include "nsIThread.h"
14 class nsHtml5Atom;
16 class nsHtml5AtomEntry : public nsStringHashKey
17 {
18 public:
19 nsHtml5AtomEntry(KeyTypePointer aStr);
20 nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther);
21 ~nsHtml5AtomEntry();
22 inline nsHtml5Atom* GetAtom()
23 {
24 return mAtom;
25 }
26 private:
27 nsAutoPtr<nsHtml5Atom> mAtom;
28 };
30 /**
31 * nsHtml5AtomTable provides non-locking lookup and creation of atoms for
32 * nsHtml5Parser or nsHtml5StreamParser.
33 *
34 * The hashtable holds dynamically allocated atoms that are private to an
35 * instance of nsHtml5Parser or nsHtml5StreamParser. (Static atoms are used on
36 * interned nsHtml5ElementNames and interned nsHtml5AttributeNames. Also, when
37 * the doctype name is 'html', that identifier needs to be represented as a
38 * static atom.)
39 *
40 * Each instance of nsHtml5Parser has a single instance of nsHtml5AtomTable,
41 * and each instance of nsHtml5StreamParser has a single instance of
42 * nsHtml5AtomTable. Dynamic atoms obtained from an nsHtml5AtomTable are valid
43 * for == comparison with each other or with atoms declared in nsHtml5Atoms
44 * within the nsHtml5Tokenizer and the nsHtml5TreeBuilder instances owned by
45 * the same nsHtml5Parser/nsHtml5StreamParser instance that owns the
46 * nsHtml5AtomTable instance.
47 *
48 * Dynamic atoms (atoms whose IsStaticAtom() returns false) obtained from
49 * nsHtml5AtomTable must be re-obtained from another atom table when there's a
50 * need to migrate atoms from an nsHtml5Parser to its nsHtml5StreamParser
51 * (re-obtain from the other nsHtml5AtomTable), from an nsHtml5Parser to its
52 * owner nsHtml5Parser (re-obtain from the other nsHtml5AtomTable) or from the
53 * parser to the DOM (re-obtain from the application-wide atom table). To
54 * re-obtain an atom from another atom table, obtain a string from the atom
55 * using ToString(nsAString&) and look up an atom in the other table using that
56 * string.
57 *
58 * An instance of nsHtml5AtomTable that belongs to an nsHtml5Parser is only
59 * accessed from the main thread. An instance of nsHtml5AtomTable that belongs
60 * to an nsHtml5StreamParser is accessed both from the main thread and from the
61 * thread that executes the runnables of the nsHtml5StreamParser instance.
62 * However, the threads never access the nsHtml5AtomTable instance concurrently
63 * in the nsHtml5StreamParser case.
64 *
65 * Methods on the atoms obtained from nsHtml5AtomTable may be called on any
66 * thread, although they only need to be called on the main thread or on the
67 * thread working for the nsHtml5StreamParser when nsHtml5AtomTable belongs to
68 * an nsHtml5StreamParser.
69 *
70 * Dynamic atoms obtained from nsHtml5AtomTable are deleted when the
71 * nsHtml5AtomTable itself is destructed, which happens when the owner
72 * nsHtml5Parser or nsHtml5StreamParser is destructed.
73 */
74 class nsHtml5AtomTable
75 {
76 public:
77 nsHtml5AtomTable();
78 ~nsHtml5AtomTable();
80 /**
81 * Obtains the atom for the given string in the scope of this atom table.
82 */
83 nsIAtom* GetAtom(const nsAString& aKey);
85 /**
86 * Empties the table.
87 */
88 void Clear()
89 {
90 mTable.Clear();
91 }
93 #ifdef DEBUG
94 void SetPermittedLookupThread(nsIThread* aThread)
95 {
96 mPermittedLookupThread = aThread;
97 }
98 #endif
100 private:
101 nsTHashtable<nsHtml5AtomEntry> mTable;
102 #ifdef DEBUG
103 nsCOMPtr<nsIThread> mPermittedLookupThread;
104 #endif
105 };
107 #endif // nsHtml5AtomTable_h