Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/ds/nsClassHashtable.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef nsClassHashtable_h__
8
#define nsClassHashtable_h__
9
10
#include "mozilla/Move.h"
11
#include "nsBaseHashtable.h"
12
#include "nsHashKeys.h"
13
#include "nsAutoPtr.h"
14
15
/**
16
 * templated hashtable class maps keys to C++ object pointers.
17
 * See nsBaseHashtable for complete declaration.
18
 * @param KeyClass a wrapper-class for the hashtable key, see nsHashKeys.h
19
 *   for a complete specification.
20
 * @param Class the class-type being wrapped
21
 * @see nsInterfaceHashtable, nsClassHashtable
22
 */
23
template<class KeyClass, class T>
24
class nsClassHashtable
25
  : public nsBaseHashtable<KeyClass, nsAutoPtr<T>, T*>
26
{
27
public:
28
  typedef typename KeyClass::KeyType KeyType;
29
  typedef T* UserDataType;
30
  typedef nsBaseHashtable<KeyClass, nsAutoPtr<T>, T*> base_type;
31
32
  using base_type::IsEmpty;
33
  using base_type::Remove;
34
35
9
  nsClassHashtable() {}
nsClassHashtable<nsUint32HashKey, nsTString<char> >::nsClassHashtable()
Line
Count
Source
35
3
  nsClassHashtable() {}
nsClassHashtable<nsDepCharHashKey, CategoryNode>::nsClassHashtable()
Line
Count
Source
35
3
  nsClassHashtable() {}
nsClassHashtable<nsCStringHashKey, nsComponentManagerImpl::KnownModule>::nsClassHashtable()
Line
Count
Source
35
3
  nsClassHashtable() {}
Unexecuted instantiation: nsClassHashtable<nsStringHashKey, nsAutoTObserverArray<nsMessageListenerInfo, 1ul> >::nsClassHashtable()
Unexecuted instantiation: nsClassHashtable<nsRefPtrHashKey<nsAtom>, nsTHashtable<nsRefPtrHashKey<nsIWeakReference> > >::nsClassHashtable()
Unexecuted instantiation: nsClassHashtable<nsPtrHashKey<gfxFontEntry>, mozilla::dom::InspectorFontFace>::nsClassHashtable()
36
  explicit nsClassHashtable(uint32_t aInitLength)
37
    : nsBaseHashtable<KeyClass, nsAutoPtr<T>, T*>(aInitLength)
38
3
  {
39
3
  }
nsClassHashtable<nsCharPtrHashKey, mozilla::LogModule>::nsClassHashtable(unsigned int)
Line
Count
Source
38
3
  {
39
3
  }
Unexecuted instantiation: nsClassHashtable<nsDepCharHashKey, BloatEntry>::nsClassHashtable(unsigned int)
Unexecuted instantiation: nsClassHashtable<nsPtrHashKey<void const>, SerialNumberRecord>::nsClassHashtable(unsigned int)
40
41
  /**
42
   * Looks up aKey in the hash table. If it doesn't exist a new object of
43
   * KeyClass will be created (using the arguments provided) and then returned.
44
   */
45
  template<typename... Args>
46
  UserDataType LookupOrAdd(KeyType aKey, Args&&... aConstructionArgs);
47
48
  /**
49
   * @copydoc nsBaseHashtable::Get
50
   * @param aData if the key doesn't exist, pData will be set to nullptr.
51
   */
52
  bool Get(KeyType aKey, UserDataType* aData) const;
53
54
  /**
55
   * @copydoc nsBaseHashtable::Get
56
   * @returns nullptr if the key is not present.
57
   */
58
  UserDataType Get(KeyType aKey) const;
59
};
60
61
template<typename K, typename T>
62
inline void
63
ImplCycleCollectionUnlink(nsClassHashtable<K, T>& aField)
64
0
{
65
0
  aField.Clear();
66
0
}
67
68
template<typename K, typename T>
69
inline void
70
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
71
                            const nsClassHashtable<K, T>& aField,
72
                            const char* aName,
73
                            uint32_t aFlags = 0)
74
0
{
75
0
  for (auto iter = aField.ConstIter(); !iter.Done(); iter.Next()) {
76
0
    ImplCycleCollectionTraverse(aCallback, *iter.UserData(), aName, aFlags);
77
0
  }
78
0
}
79
80
//
81
// nsClassHashtable definitions
82
//
83
84
template<class KeyClass, class T>
85
template<typename... Args>
86
T*
87
nsClassHashtable<KeyClass, T>::LookupOrAdd(KeyType aKey,
88
                                           Args&&... aConstructionArgs)
89
0
{
90
0
  auto count = this->Count();
91
0
  typename base_type::EntryType* ent = this->PutEntry(aKey);
92
0
  if (count != this->Count()) {
93
0
    ent->mData = new T(std::forward<Args>(aConstructionArgs)...);
94
0
  }
95
0
  return ent->mData;
96
0
}
97
98
template<class KeyClass, class T>
99
bool
100
nsClassHashtable<KeyClass, T>::Get(KeyType aKey, T** aRetVal) const
101
455
{
102
455
  typename base_type::EntryType* ent = this->GetEntry(aKey);
103
455
104
455
  if (ent) {
105
283
    if (aRetVal) {
106
283
      *aRetVal = ent->mData;
107
283
    }
108
283
109
283
    return true;
110
283
  }
111
172
112
172
  if (aRetVal) {
113
172
    *aRetVal = nullptr;
114
172
  }
115
172
116
172
  return false;
117
172
}
nsClassHashtable<nsCharPtrHashKey, mozilla::LogModule>::Get(char const*, mozilla::LogModule**) const
Line
Count
Source
101
75
{
102
75
  typename base_type::EntryType* ent = this->GetEntry(aKey);
103
75
104
75
  if (ent) {
105
0
    if (aRetVal) {
106
0
      *aRetVal = ent->mData;
107
0
    }
108
0
109
0
    return true;
110
0
  }
111
75
112
75
  if (aRetVal) {
113
75
    *aRetVal = nullptr;
114
75
  }
115
75
116
75
  return false;
117
75
}
Unexecuted instantiation: nsClassHashtable<nsCharPtrHashKey, nsINIParser_internal::INIValue>::Get(char const*, nsINIParser_internal::INIValue**) const
nsClassHashtable<nsDepCharHashKey, CategoryNode>::Get(char const*, CategoryNode**) const
Line
Count
Source
101
380
{
102
380
  typename base_type::EntryType* ent = this->GetEntry(aKey);
103
380
104
380
  if (ent) {
105
283
    if (aRetVal) {
106
283
      *aRetVal = ent->mData;
107
283
    }
108
283
109
283
    return true;
110
283
  }
111
97
112
97
  if (aRetVal) {
113
97
    *aRetVal = nullptr;
114
97
  }
115
97
116
97
  return false;
117
97
}
Unexecuted instantiation: nsClassHashtable<nsRefPtrHashKey<nsAtom>, nsTHashtable<nsRefPtrHashKey<nsIWeakReference> > >::Get(nsAtom*, nsTHashtable<nsRefPtrHashKey<nsIWeakReference> >**) const
118
119
template<class KeyClass, class T>
120
T*
121
nsClassHashtable<KeyClass, T>::Get(KeyType aKey) const
122
327
{
123
327
  typename base_type::EntryType* ent = this->GetEntry(aKey);
124
327
  if (!ent) {
125
240
    return nullptr;
126
240
  }
127
87
128
87
  return ent->mData;
129
87
}
Unexecuted instantiation: nsClassHashtable<nsUint32HashKey, nsTString<char> >::Get(unsigned int const&) const
Unexecuted instantiation: nsClassHashtable<nsDepCharHashKey, BloatEntry>::Get(char const*) const
Unexecuted instantiation: nsClassHashtable<nsPtrHashKey<void const>, SerialNumberRecord>::Get(void const*) const
nsClassHashtable<nsCStringHashKey, nsComponentManagerImpl::KnownModule>::Get(nsTSubstring<char> const&) const
Line
Count
Source
122
327
{
123
327
  typename base_type::EntryType* ent = this->GetEntry(aKey);
124
327
  if (!ent) {
125
240
    return nullptr;
126
240
  }
127
87
128
87
  return ent->mData;
129
87
}
Unexecuted instantiation: nsClassHashtable<nsStringHashKey, nsAutoTObserverArray<nsMessageListenerInfo, 1ul> >::Get(nsTSubstring<char16_t> const&) const
130
131
#endif // nsClassHashtable_h__