Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / base / nsCycleCollectionNoteChild.h
blob3e1d345aa31cfc98866558c77761cd77261b85f5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // This header will be included by headers that define refpointer and array
8 // classes in order to specialize CC helpers such as ImplCycleCollectionTraverse
9 // for them.
11 #ifndef nsCycleCollectionNoteChild_h__
12 #define nsCycleCollectionNoteChild_h__
14 #include "nsCycleCollectionTraversalCallback.h"
15 #include "mozilla/Likely.h"
17 enum { CycleCollectionEdgeNameArrayFlag = 1 };
19 // Just a helper for appending "[i]". Didn't want to pull in string headers
20 // here.
21 void CycleCollectionNoteEdgeNameImpl(
22 nsCycleCollectionTraversalCallback& aCallback, const char* aName,
23 uint32_t aFlags = 0);
25 // Should be inlined so that in the no-debug-info case this is just a simple
26 // if().
27 MOZ_ALWAYS_INLINE void CycleCollectionNoteEdgeName(
28 nsCycleCollectionTraversalCallback& aCallback, const char* aName,
29 uint32_t aFlags = 0) {
30 if (MOZ_UNLIKELY(aCallback.WantDebugInfo())) {
31 CycleCollectionNoteEdgeNameImpl(aCallback, aName, aFlags);
35 #define NS_CYCLE_COLLECTION_INNERCLASS cycleCollection
37 #define NS_CYCLE_COLLECTION_INNERNAME _cycleCollectorGlobal
39 #define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \
40 _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()
42 template <typename T>
43 nsISupports* ToSupports(
44 T* aPtr, typename T::NS_CYCLE_COLLECTION_INNERCLASS* aDummy = 0) {
45 return T::NS_CYCLE_COLLECTION_INNERCLASS::Upcast(aPtr);
48 // The default implementation of this class template is empty, because it
49 // should never be used: see the partial specializations below.
50 template <typename T, bool IsXPCOM = std::is_base_of<nsISupports, T>::value>
51 struct CycleCollectionNoteChildImpl {};
53 template <typename T>
54 struct CycleCollectionNoteChildImpl<T, true> {
55 static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) {
56 aCallback.NoteXPCOMChild(ToSupports(aChild));
60 template <typename T>
61 struct CycleCollectionNoteChildImpl<T, false> {
62 static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) {
63 aCallback.NoteNativeChild(aChild, NS_CYCLE_COLLECTION_PARTICIPANT(T));
67 // We declare CycleCollectionNoteChild in 3-argument and 4-argument variants,
68 // rather than using default arguments, so that forward declarations work
69 // regardless of header inclusion order.
70 template <typename T>
71 inline void CycleCollectionNoteChild(
72 nsCycleCollectionTraversalCallback& aCallback, T* aChild, const char* aName,
73 uint32_t aFlags) {
74 CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
75 CycleCollectionNoteChildImpl<T>::Run(aCallback, aChild);
78 template <typename T>
79 inline void CycleCollectionNoteChild(
80 nsCycleCollectionTraversalCallback& aCallback, T* aChild,
81 const char* aName) {
82 CycleCollectionNoteChild(aCallback, aChild, aName, 0);
85 #endif // nsCycleCollectionNoteChild_h__