xpcom/glue/nsCycleCollectionNoteChild.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/glue/nsCycleCollectionNoteChild.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +// This header will be included by headers that define refpointer and array classes
    1.10 +// in order to specialize CC helpers such as ImplCycleCollectionTraverse for them.
    1.11 +
    1.12 +#ifndef nsCycleCollectionNoteChild_h__
    1.13 +#define nsCycleCollectionNoteChild_h__
    1.14 +
    1.15 +#include "nsCycleCollectionTraversalCallback.h"
    1.16 +#include "mozilla/Likely.h"
    1.17 +#include "mozilla/TypeTraits.h"
    1.18 +
    1.19 +enum {
    1.20 +  CycleCollectionEdgeNameArrayFlag = 1
    1.21 +};
    1.22 +
    1.23 +// Just a helper for appending "[i]". Didn't want to pull in string headers here.
    1.24 +void
    1.25 +CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback,
    1.26 +                                const char* aName,
    1.27 +                                uint32_t aFlags = 0);
    1.28 +
    1.29 +// Should be inlined so that in the no-debug-info case this is just a simple if().
    1.30 +MOZ_ALWAYS_INLINE void
    1.31 +CycleCollectionNoteEdgeName(nsCycleCollectionTraversalCallback& aCallback,
    1.32 +                            const char* aName,
    1.33 +                            uint32_t aFlags = 0)
    1.34 +{
    1.35 +  if (MOZ_UNLIKELY(aCallback.WantDebugInfo())) {
    1.36 +    CycleCollectionNoteEdgeNameImpl(aCallback, aName, aFlags);
    1.37 +  }
    1.38 +}
    1.39 +
    1.40 +#define NS_CYCLE_COLLECTION_INNERCLASS                                         \
    1.41 +        cycleCollection
    1.42 +
    1.43 +#define NS_CYCLE_COLLECTION_INNERNAME                                          \
    1.44 +        _cycleCollectorGlobal
    1.45 +
    1.46 +#define NS_CYCLE_COLLECTION_PARTICIPANT(_class)                                \
    1.47 +        _class::NS_CYCLE_COLLECTION_INNERCLASS::GetParticipant()
    1.48 +
    1.49 +template <typename T>
    1.50 +nsISupports* ToSupports(T* p, typename T::NS_CYCLE_COLLECTION_INNERCLASS* dummy = 0)
    1.51 +{
    1.52 +  return T::NS_CYCLE_COLLECTION_INNERCLASS::Upcast(p);
    1.53 +}
    1.54 +
    1.55 +// The default implementation of this class template is empty, because it
    1.56 +// should never be used: see the partial specializations below.
    1.57 +template <typename T,
    1.58 +          bool IsXPCOM = mozilla::IsBaseOf<nsISupports, T>::value>
    1.59 +struct CycleCollectionNoteChildImpl
    1.60 +{
    1.61 +};
    1.62 +
    1.63 +template <typename T>
    1.64 +struct CycleCollectionNoteChildImpl<T, true>
    1.65 +{
    1.66 +  static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild)
    1.67 +  {
    1.68 +    aCallback.NoteXPCOMChild(ToSupports(aChild));
    1.69 +  }
    1.70 +};
    1.71 +
    1.72 +template <typename T>
    1.73 +struct CycleCollectionNoteChildImpl<T, false>
    1.74 +{
    1.75 +  static void Run(nsCycleCollectionTraversalCallback& aCallback, T* aChild)
    1.76 +  {
    1.77 +    aCallback.NoteNativeChild(aChild, NS_CYCLE_COLLECTION_PARTICIPANT(T));
    1.78 +  }
    1.79 +};
    1.80 +
    1.81 +template <typename T>
    1.82 +inline void CycleCollectionNoteChild(nsCycleCollectionTraversalCallback& aCallback,
    1.83 +                                     T* aChild,
    1.84 +                                     const char* aName,
    1.85 +                                     uint32_t aFlags = 0)
    1.86 +{
    1.87 +  CycleCollectionNoteEdgeName(aCallback, aName, aFlags);
    1.88 +  CycleCollectionNoteChildImpl<T>::Run(aCallback, aChild);
    1.89 +}
    1.90 +
    1.91 +#endif // nsCycleCollectionNoteChild_h__

mercurial