Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 560764e

Browse files
committed
Bug 1940869 - Use STL types in dom/canvas/CacheInvalidator.h. r=gfx-reviewers,lsalzman
Differential Revision: https://phabricator.services.mozilla.com/D233785
1 parent 4f79119 commit 560764e

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

dom/canvas/CacheInvalidator.h

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
#ifndef MOZILLA_CACHE_INVALIDATOR_H_
88
#define MOZILLA_CACHE_INVALIDATOR_H_
99

10-
#include "mozilla/Maybe.h"
11-
#include "mozilla/UniquePtr.h"
1210
#include "DmdStdContainers.h"
11+
#include "mozilla/Assertions.h"
12+
13+
#include <cstddef> // nullptr_t
14+
#include <memory>
15+
#include <optional>
1316
#include <vector>
1417

1518
// -
@@ -73,27 +76,33 @@ class AbstractCache {
7376

7477
template <typename T>
7578
class CacheMaybe : public AbstractCache {
76-
Maybe<T> mVal;
79+
std::optional<T> mVal;
7780

7881
public:
82+
CacheMaybe& operator=(std::optional<T>&& rhs) {
83+
mVal.swap(rhs);
84+
rhs.reset();
85+
return *this;
86+
}
87+
7988
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));
8591
return *this;
8692
}
8793

88-
CacheMaybe& operator=(Nothing) { return *this = Maybe<T>(); }
94+
CacheMaybe& operator=(std::nullptr_t) {
95+
mVal.reset();
96+
return *this;
97+
}
8998

9099
void OnInvalidate() override {
91-
*this = Nothing();
100+
*this = {};
92101
ResetInvalidators({});
93102
}
94103

95104
explicit operator bool() const { return bool(mVal); }
96-
T* get() const { return mVal.ptrOr(nullptr); }
105+
T* get() const { return mVal ? &*mVal : nullptr; }
97106
T* operator->() const { return get(); }
98107
};
99108

@@ -127,7 +136,7 @@ class CacheWeakMap final {
127136
}
128137
};
129138

130-
using MapT = webgl::dmd_unordered_map<const KeyT*, UniquePtr<Entry>,
139+
using MapT = webgl::dmd_unordered_map<const KeyT*, std::unique_ptr<Entry>,
131140
DerefHash, DerefEqual>;
132141
MapT mMap;
133142

@@ -136,14 +145,14 @@ class CacheWeakMap final {
136145
return mMap.SizeOfExcludingThis(mso);
137146
}
138147

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)));
141150
}
142-
UniquePtr<Entry> MakeEntry(const KeyT& key, const ValueT& value) {
151+
std::unique_ptr<Entry> MakeEntry(const KeyT& key, const ValueT& value) {
143152
return MakeEntry(key, ValueT(value));
144153
}
145154

146-
const ValueT* Insert(UniquePtr<Entry>&& entry) {
155+
const ValueT* Insert(std::unique_ptr<Entry>&& entry) {
147156
auto insertable = typename MapT::value_type{&entry->mKey, std::move(entry)};
148157

149158
const auto res = mMap.insert(std::move(insertable));

dom/canvas/WebGLFramebuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ WebGLFramebuffer::WebGLFramebuffer(WebGLContext* webgl,
522522
info.zLayerCount = 1;
523523
info.isMultiview = false;
524524

525-
mCompletenessInfo = Some(std::move(info));
525+
mCompletenessInfo = std::move(info);
526526
}
527527

528528
WebGLFramebuffer::~WebGLFramebuffer() {
@@ -1062,7 +1062,7 @@ FBStatus WebGLFramebuffer::CheckFramebufferStatus() const {
10621062
info.isMultiview = cur->IsMultiview();
10631063
}
10641064
MOZ_ASSERT(info.width && info.height);
1065-
mCompletenessInfo = Some(std::move(info));
1065+
mCompletenessInfo = std::move(info);
10661066
info.fb = nullptr; // Don't trigger the invalidation warning.
10671067
return LOCAL_GL_FRAMEBUFFER_COMPLETE;
10681068
} while (false);

0 commit comments

Comments
 (0)