[clang] c7987d4 - [ADT] Use value instead of getValue() (NFC)

Kazu Hirata via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 19 18:34:39 PDT 2022


Author: Kazu Hirata
Date: 2022-06-19T18:34:33-07:00
New Revision: c7987d49483685a29c3004c8710011a35cbb53e1

URL: https://github.com/llvm/llvm-project/commit/c7987d49483685a29c3004c8710011a35cbb53e1
DIFF: https://github.com/llvm/llvm-project/commit/c7987d49483685a29c3004c8710011a35cbb53e1.diff

LOG: [ADT] Use value instead of getValue() (NFC)

Since Optional<clang::FileEntryRef> uses a custom storage class, this
patch adds value to MapEntryOptionalStorage.

Added: 
    

Modified: 
    clang/include/clang/Basic/DirectoryEntry.h
    llvm/include/llvm/ADT/Optional.h

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h
index 0cfdb1d73eef..d54b81d2e6e7 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -133,14 +133,26 @@ template <class RefTy> class MapEntryOptionalStorage {
   bool has_value() const { return MaybeRef.hasOptionalValue(); }
   bool hasValue() const { return MaybeRef.hasOptionalValue(); }
 
+  RefTy &value() & {
+    assert(has_value());
+    return MaybeRef;
+  }
   RefTy &getValue() & {
     assert(hasValue());
     return MaybeRef;
   }
+  RefTy const &value() const & {
+    assert(has_value());
+    return MaybeRef;
+  }
   RefTy const &getValue() const & {
     assert(hasValue());
     return MaybeRef;
   }
+  RefTy &&value() && {
+    assert(has_value());
+    return std::move(MaybeRef);
+  }
   RefTy &&getValue() && {
     assert(hasValue());
     return std::move(MaybeRef);

diff  --git a/llvm/include/llvm/ADT/Optional.h b/llvm/include/llvm/ADT/Optional.h
index 62765914eb66..d1615d903e98 100644
--- a/llvm/include/llvm/ADT/Optional.h
+++ b/llvm/include/llvm/ADT/Optional.h
@@ -300,53 +300,53 @@ template <typename T> class Optional {
 
   void reset() { Storage.reset(); }
 
-  constexpr const T *getPointer() const { return &Storage.getValue(); }
-  T *getPointer() { return &Storage.getValue(); }
-  constexpr const T &value() const & { return Storage.getValue(); }
-  constexpr const T &getValue() const & { return Storage.getValue(); }
-  T &value() & { return Storage.getValue(); }
-  T &getValue() & { return Storage.getValue(); }
+  constexpr const T *getPointer() const { return &Storage.value(); }
+  T *getPointer() { return &Storage.value(); }
+  constexpr const T &value() const & { return Storage.value(); }
+  constexpr const T &getValue() const & { return Storage.value(); }
+  T &value() & { return Storage.value(); }
+  T &getValue() & { return Storage.value(); }
 
   constexpr explicit operator bool() const { return has_value(); }
   constexpr bool has_value() const { return Storage.has_value(); }
   constexpr bool hasValue() const { return Storage.has_value(); }
   constexpr const T *operator->() const { return getPointer(); }
   T *operator->() { return getPointer(); }
-  constexpr const T &operator*() const & { return getValue(); }
-  T &operator*() & { return getValue(); }
+  constexpr const T &operator*() const & { return value(); }
+  T &operator*() & { return value(); }
 
   template <typename U> constexpr T value_or(U &&alt) const & {
-    return has_value() ? getValue() : std::forward<U>(alt);
+    return has_value() ? value() : std::forward<U>(alt);
   }
   template <typename U> constexpr T getValueOr(U &&alt) const & {
-    return has_value() ? getValue() : std::forward<U>(alt);
+    return has_value() ? value() : std::forward<U>(alt);
   }
 
   /// Apply a function to the value if present; otherwise return None.
   template <class Function>
-  auto map(const Function &F) const & -> Optional<decltype(F(getValue()))> {
+  auto map(const Function &F) const & -> Optional<decltype(F(value()))> {
     if (*this)
-      return F(getValue());
+      return F(value());
     return None;
   }
 
-  T &&value() && { return std::move(Storage.getValue()); }
-  T &&getValue() && { return std::move(Storage.getValue()); }
-  T &&operator*() && { return std::move(Storage.getValue()); }
+  T &&value() && { return std::move(Storage.value()); }
+  T &&getValue() && { return std::move(Storage.value()); }
+  T &&operator*() && { return std::move(Storage.value()); }
 
   template <typename U> T value_or(U &&alt) && {
-    return has_value() ? std::move(getValue()) : std::forward<U>(alt);
+    return has_value() ? std::move(value()) : std::forward<U>(alt);
   }
   template <typename U> T getValueOr(U &&alt) && {
-    return has_value() ? std::move(getValue()) : std::forward<U>(alt);
+    return has_value() ? std::move(value()) : std::forward<U>(alt);
   }
 
   /// Apply a function to the value if present; otherwise return None.
   template <class Function>
   auto map(const Function &F)
-      && -> Optional<decltype(F(std::move(*this).getValue()))> {
+      && -> Optional<decltype(F(std::move(*this).value()))> {
     if (*this)
-      return F(std::move(*this).getValue());
+      return F(std::move(*this).value());
     return None;
   }
 };


        


More information about the cfe-commits mailing list