File: nsCycleCollectionNoteChild.h

package info (click to toggle)
firefox 146.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,653,260 kB
  • sloc: cpp: 7,587,892; javascript: 6,509,455; ansic: 3,755,295; python: 1,410,813; xml: 629,201; asm: 438,677; java: 186,096; sh: 62,697; makefile: 18,086; objc: 13,087; perl: 12,811; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (87 lines) | stat: -rw-r--r-- 3,123 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// This header will be included by headers that define refpointer and array
// classes in order to specialize CC helpers such as ImplCycleCollectionTraverse
// for them.

#ifndef nsCycleCollectionNoteChild_h__
#define nsCycleCollectionNoteChild_h__

#include "nsCycleCollectionTraversalCallback.h"
#include "mozilla/Likely.h"

#include <type_traits>

enum { CycleCollectionEdgeNameArrayFlag = 1 };

// Just a helper for appending "[i]". Didn't want to pull in string headers
// here.
void CycleCollectionNoteEdgeNameImpl(
    nsCycleCollectionTraversalCallback& aCallback, const char* aName,
    uint32_t aFlags = 0);

// Should be inlined so that in the no-debug-info case this is just a simple
// if().
MOZ_ALWAYS_INLINE void CycleCollectionNoteEdgeName(
    nsCycleCollectionTraversalCallback& aCallback, const char* aName,
    uint32_t aFlags = 0) {
  if (MOZ_UNLIKELY(aCallback.WantDebugInfo())) {
    CycleCollectionNoteEdgeNameImpl(aCallback, aName, aFlags);
  }
}

#define NS_CYCLE_COLLECTION_INNERCLASS cycleCollection

#define NS_CYCLE_COLLECTION_INNERNAME _cycleCollectorGlobal

#define NS_CYCLE_COLLECTION_PARTICIPANT(_class) \
  _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()

template <typename T>
nsISupports* ToSupports(
    T* aPtr, typename T::NS_CYCLE_COLLECTION_INNERCLASS* aDummy = 0) {
  return T::NS_CYCLE_COLLECTION_INNERCLASS::Upcast(aPtr);
}

// The default implementation of this class template is empty, because it
// should never be used: see the partial specializations below.
template <typename T, bool IsXPCOM = std::is_base_of<nsISupports, T>::value>
struct CycleCollectionNoteChildImpl {};

template <typename T>
struct CycleCollectionNoteChildImpl<T, true> {
  static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) {
    aCallback.NoteXPCOMChild(ToSupports(aChild));
  }
};

template <typename T>
struct CycleCollectionNoteChildImpl<T, false> {
  static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild) {
    aCallback.NoteNativeChild(aChild, NS_CYCLE_COLLECTION_PARTICIPANT(T));
  }
};

// We declare CycleCollectionNoteChild in 3-argument and 4-argument variants,
// rather than using default arguments, so that forward declarations work
// regardless of header inclusion order.
template <typename T>
inline void CycleCollectionNoteChild(
    nsCycleCollectionTraversalCallback& aCallback, T* aChild, const char* aName,
    uint32_t aFlags) {
  CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
  CycleCollectionNoteChildImpl<T>::Run(aCallback, aChild);
}

template <typename T>
inline void CycleCollectionNoteChild(
    nsCycleCollectionTraversalCallback& aCallback, T* aChild,
    const char* aName) {
  CycleCollectionNoteChild(aCallback, aChild, aName, 0);
}

#endif  // nsCycleCollectionNoteChild_h__