Line data Source code
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/. */
6 :
7 : // This header will be included by headers that define refpointer and array classes
8 : // in order to specialize CC helpers such as ImplCycleCollectionTraverse for them.
9 :
10 : #ifndef nsCycleCollectionNoteChild_h__
11 : #define nsCycleCollectionNoteChild_h__
12 :
13 : #include "nsCycleCollectionTraversalCallback.h"
14 : #include "mozilla/Likely.h"
15 : #include "mozilla/TypeTraits.h"
16 :
17 : enum
18 : {
19 : CycleCollectionEdgeNameArrayFlag = 1
20 : };
21 :
22 : // Just a helper for appending "[i]". Didn't want to pull in string headers here.
23 : void
24 : CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback,
25 : const char* aName,
26 : uint32_t aFlags = 0);
27 :
28 : // Should be inlined so that in the no-debug-info case this is just a simple if().
29 : MOZ_ALWAYS_INLINE void
30 13532 : CycleCollectionNoteEdgeName(nsCycleCollectionTraversalCallback& aCallback,
31 : const char* aName,
32 : uint32_t aFlags = 0)
33 : {
34 13532 : if (MOZ_UNLIKELY(aCallback.WantDebugInfo())) {
35 0 : CycleCollectionNoteEdgeNameImpl(aCallback, aName, aFlags);
36 : }
37 13532 : }
38 :
39 : #define NS_CYCLE_COLLECTION_INNERCLASS \
40 : cycleCollection
41 :
42 : #define NS_CYCLE_COLLECTION_INNERNAME \
43 : _cycleCollectorGlobal
44 :
45 : #define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \
46 : _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()
47 :
48 : template<typename T>
49 : nsISupports*
50 6309 : ToSupports(T* aPtr, typename T::NS_CYCLE_COLLECTION_INNERCLASS* aDummy = 0)
51 : {
52 6309 : return T::NS_CYCLE_COLLECTION_INNERCLASS::Upcast(aPtr);
53 : }
54 :
55 : // The default implementation of this class template is empty, because it
56 : // should never be used: see the partial specializations below.
57 : template<typename T,
58 : bool IsXPCOM = mozilla::IsBaseOf<nsISupports, T>::value>
59 : struct CycleCollectionNoteChildImpl
60 : {
61 : };
62 :
63 : template<typename T>
64 : struct CycleCollectionNoteChildImpl<T, true>
65 : {
66 5293 : static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild)
67 : {
68 5293 : aCallback.NoteXPCOMChild(ToSupports(aChild));
69 5293 : }
70 : };
71 :
72 : template<typename T>
73 : struct CycleCollectionNoteChildImpl<T, false>
74 : {
75 710 : static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild)
76 : {
77 710 : aCallback.NoteNativeChild(aChild, NS_CYCLE_COLLECTION_PARTICIPANT(T));
78 710 : }
79 : };
80 :
81 : // We declare CycleCollectionNoteChild in 3-argument and 4-argument variants,
82 : // rather than using default arguments, so that forward declarations work
83 : // regardless of header inclusion order.
84 : template<typename T>
85 : inline void
86 6003 : CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
87 : T* aChild, const char* aName, uint32_t aFlags)
88 : {
89 6003 : CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
90 6003 : CycleCollectionNoteChildImpl<T>::Run(aCallback, aChild);
91 6003 : }
92 :
93 : template<typename T>
94 : inline void
95 626 : CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
96 : T* aChild, const char* aName)
97 : {
98 626 : CycleCollectionNoteChild(aCallback, aChild, aName, 0);
99 626 : }
100 :
101 : #endif // nsCycleCollectionNoteChild_h__
|