Bug 1867925 - Mark some storage-access-api tests as intermittent after wpt-sync....
[gecko.git] / parser / html / nsHtml5AtomTable.h
blob2f63eaafcbf2f23d25bce5e5c1a1c8688c2145cd
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 "nsAtom.h"
11 #include "nsISerialEventTarget.h"
13 #define RECENTLY_USED_PARSER_ATOMS_SIZE 37
16 * nsHtml5AtomTable provides an atom cache for nsHtml5Parser and
17 * nsHtml5StreamParser.
19 * An instance of nsHtml5AtomTable that belongs to an nsHtml5Parser is only
20 * accessed from the main thread. An instance of nsHtml5AtomTable that belongs
21 * to an nsHtml5StreamParser is accessed both from the main thread and from the
22 * thread that executes the runnables of the nsHtml5StreamParser instance.
23 * However, the threads never access the nsHtml5AtomTable instance concurrently
24 * in the nsHtml5StreamParser case.
26 * Methods on the atoms obtained from nsHtml5AtomTable may be called on any
27 * thread, although they only need to be called on the main thread or on the
28 * thread working for the nsHtml5StreamParser when nsHtml5AtomTable belongs to
29 * an nsHtml5StreamParser.
31 * Atoms cached by nsHtml5AtomTable are released when Clear() is called or when
32 * the nsHtml5AtomTable itself is destructed, which happens when the owner
33 * nsHtml5Parser or nsHtml5StreamParser is destructed.
35 class nsHtml5AtomTable {
36 public:
37 nsHtml5AtomTable();
38 ~nsHtml5AtomTable();
40 // NOTE: We rely on mRecentlyUsedParserAtoms keeping alive the returned atom,
41 // but the caller is responsible to take a reference before calling GetAtom
42 // again.
43 nsAtom* GetAtom(const nsAString& aKey);
45 /**
46 * Empties the table.
48 void Clear() {
49 for (uint32_t i = 0; i < RECENTLY_USED_PARSER_ATOMS_SIZE; ++i) {
50 mRecentlyUsedParserAtoms[i] = nullptr;
54 #ifdef DEBUG
55 void SetPermittedLookupEventTarget(nsISerialEventTarget* aEventTarget) {
56 mPermittedLookupEventTarget = aEventTarget;
58 #endif
60 private:
61 RefPtr<nsAtom> mRecentlyUsedParserAtoms[RECENTLY_USED_PARSER_ATOMS_SIZE];
62 #ifdef DEBUG
63 nsCOMPtr<nsISerialEventTarget> mPermittedLookupEventTarget;
64 #endif
67 #endif // nsHtml5AtomTable_h