Skip to content

Commit 9f54baa

Browse files
kazutakahiratabenlangmuir
authored andcommitted
[ADT] Use value instead of getValue() (NFC)
Since Optional<clang::FileEntryRef> uses a custom storage class, this patch adds value to MapEntryOptionalStorage. (cherry picked from commit c7987d4)
1 parent 5cc641e commit 9f54baa

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

clang/include/clang/Basic/DirectoryEntry.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,26 @@ template <class RefTy> class MapEntryOptionalStorage {
133133
bool has_value() const { return MaybeRef.hasOptionalValue(); }
134134
bool hasValue() const { return MaybeRef.hasOptionalValue(); }
135135

136+
RefTy &value() & {
137+
assert(has_value());
138+
return MaybeRef;
139+
}
136140
RefTy &getValue() & {
137141
assert(hasValue());
138142
return MaybeRef;
139143
}
144+
RefTy const &value() const & {
145+
assert(has_value());
146+
return MaybeRef;
147+
}
140148
RefTy const &getValue() const & {
141149
assert(hasValue());
142150
return MaybeRef;
143151
}
152+
RefTy &&value() && {
153+
assert(has_value());
154+
return std::move(MaybeRef);
155+
}
144156
RefTy &&getValue() && {
145157
assert(hasValue());
146158
return std::move(MaybeRef);

llvm/include/llvm/ADT/Optional.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,53 +300,53 @@ template <typename T> class Optional {
300300

301301
void reset() { Storage.reset(); }
302302

303-
constexpr const T *getPointer() const { return &Storage.getValue(); }
304-
T *getPointer() { return &Storage.getValue(); }
305-
constexpr const T &value() const & { return Storage.getValue(); }
306-
constexpr const T &getValue() const & { return Storage.getValue(); }
307-
T &value() & { return Storage.getValue(); }
308-
T &getValue() & { return Storage.getValue(); }
303+
constexpr const T *getPointer() const { return &Storage.value(); }
304+
T *getPointer() { return &Storage.value(); }
305+
constexpr const T &value() const & { return Storage.value(); }
306+
constexpr const T &getValue() const & { return Storage.value(); }
307+
T &value() & { return Storage.value(); }
308+
T &getValue() & { return Storage.value(); }
309309

310310
constexpr explicit operator bool() const { return has_value(); }
311311
constexpr bool has_value() const { return Storage.has_value(); }
312312
constexpr bool hasValue() const { return Storage.has_value(); }
313313
constexpr const T *operator->() const { return getPointer(); }
314314
T *operator->() { return getPointer(); }
315-
constexpr const T &operator*() const & { return getValue(); }
316-
T &operator*() & { return getValue(); }
315+
constexpr const T &operator*() const & { return value(); }
316+
T &operator*() & { return value(); }
317317

318318
template <typename U> constexpr T value_or(U &&alt) const & {
319-
return has_value() ? getValue() : std::forward<U>(alt);
319+
return has_value() ? value() : std::forward<U>(alt);
320320
}
321321
template <typename U> constexpr T getValueOr(U &&alt) const & {
322-
return has_value() ? getValue() : std::forward<U>(alt);
322+
return has_value() ? value() : std::forward<U>(alt);
323323
}
324324

325325
/// Apply a function to the value if present; otherwise return None.
326326
template <class Function>
327-
auto map(const Function &F) const & -> Optional<decltype(F(getValue()))> {
327+
auto map(const Function &F) const & -> Optional<decltype(F(value()))> {
328328
if (*this)
329-
return F(getValue());
329+
return F(value());
330330
return None;
331331
}
332332

333-
T &&value() && { return std::move(Storage.getValue()); }
334-
T &&getValue() && { return std::move(Storage.getValue()); }
335-
T &&operator*() && { return std::move(Storage.getValue()); }
333+
T &&value() && { return std::move(Storage.value()); }
334+
T &&getValue() && { return std::move(Storage.value()); }
335+
T &&operator*() && { return std::move(Storage.value()); }
336336

337337
template <typename U> T value_or(U &&alt) && {
338-
return has_value() ? std::move(getValue()) : std::forward<U>(alt);
338+
return has_value() ? std::move(value()) : std::forward<U>(alt);
339339
}
340340
template <typename U> T getValueOr(U &&alt) && {
341-
return has_value() ? std::move(getValue()) : std::forward<U>(alt);
341+
return has_value() ? std::move(value()) : std::forward<U>(alt);
342342
}
343343

344344
/// Apply a function to the value if present; otherwise return None.
345345
template <class Function>
346346
auto map(const Function &F)
347-
&& -> Optional<decltype(F(std::move(*this).getValue()))> {
347+
&& -> Optional<decltype(F(std::move(*this).value()))> {
348348
if (*this)
349-
return F(std::move(*this).getValue());
349+
return F(std::move(*this).value());
350350
return None;
351351
}
352352
};

0 commit comments

Comments
 (0)