7
7
#ifndef MOZILLA_CACHE_INVALIDATOR_H_
8
8
#define MOZILLA_CACHE_INVALIDATOR_H_
9
9
10
- #include " mozilla/Maybe.h"
11
- #include " mozilla/UniquePtr.h"
12
10
#include " DmdStdContainers.h"
11
+ #include " mozilla/Assertions.h"
12
+
13
+ #include < cstddef> // nullptr_t
14
+ #include < memory>
15
+ #include < optional>
13
16
#include < vector>
14
17
15
18
// -
@@ -73,27 +76,33 @@ class AbstractCache {
73
76
74
77
template <typename T>
75
78
class CacheMaybe : public AbstractCache {
76
- Maybe <T> mVal ;
79
+ std::optional <T> mVal ;
77
80
78
81
public:
82
+ CacheMaybe& operator =(std::optional<T>&& rhs) {
83
+ mVal .swap (rhs);
84
+ rhs.reset ();
85
+ return *this ;
86
+ }
87
+
79
88
template <typename U>
80
- CacheMaybe& operator =(Maybe<U>&& rhs) {
81
- mVal .reset ();
82
- if (rhs) {
83
- mVal .emplace (std::move (rhs.ref ()));
84
- }
89
+ CacheMaybe& operator =(U&& rhs) {
90
+ mVal .emplace (std::move (rhs));
85
91
return *this ;
86
92
}
87
93
88
- CacheMaybe& operator =(Nothing) { return *this = Maybe<T>(); }
94
+ CacheMaybe& operator =(std::nullptr_t ) {
95
+ mVal .reset ();
96
+ return *this ;
97
+ }
89
98
90
99
void OnInvalidate () override {
91
- *this = Nothing () ;
100
+ *this = {} ;
92
101
ResetInvalidators ({});
93
102
}
94
103
95
104
explicit operator bool () const { return bool (mVal ); }
96
- T* get () const { return mVal . ptrOr ( nullptr ) ; }
105
+ T* get () const { return mVal ? &* mVal : nullptr ; }
97
106
T* operator ->() const { return get (); }
98
107
};
99
108
@@ -127,7 +136,7 @@ class CacheWeakMap final {
127
136
}
128
137
};
129
138
130
- using MapT = webgl::dmd_unordered_map<const KeyT*, UniquePtr <Entry>,
139
+ using MapT = webgl::dmd_unordered_map<const KeyT*, std::unique_ptr <Entry>,
131
140
DerefHash, DerefEqual>;
132
141
MapT mMap ;
133
142
@@ -136,14 +145,14 @@ class CacheWeakMap final {
136
145
return mMap .SizeOfExcludingThis (mso);
137
146
}
138
147
139
- UniquePtr <Entry> MakeEntry (const KeyT& key, ValueT&& value) {
140
- return UniquePtr <Entry>(new Entry (*this , key, std::move (value)));
148
+ std::unique_ptr <Entry> MakeEntry (const KeyT& key, ValueT&& value) {
149
+ return std::unique_ptr <Entry>(new Entry (*this , key, std::move (value)));
141
150
}
142
- UniquePtr <Entry> MakeEntry (const KeyT& key, const ValueT& value) {
151
+ std::unique_ptr <Entry> MakeEntry (const KeyT& key, const ValueT& value) {
143
152
return MakeEntry (key, ValueT (value));
144
153
}
145
154
146
- const ValueT* Insert (UniquePtr <Entry>&& entry) {
155
+ const ValueT* Insert (std::unique_ptr <Entry>&& entry) {
147
156
auto insertable = typename MapT::value_type{&entry->mKey , std::move (entry)};
148
157
149
158
const auto res = mMap .insert (std::move (insertable));
0 commit comments