[Lldb-commits] [lldb] 2a3ef37 - [lldb][NFC] Don't hide a bool in LibCxxOptional's OptionalFrontend::m_size

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 10 04:03:32 PST 2020


Author: Raphael Isemann
Date: 2020-02-10T13:03:06+01:00
New Revision: 2a3ef377ec00e7c7d3f4c47614ab6baee727cd82

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

LOG: [lldb][NFC] Don't hide a bool in LibCxxOptional's OptionalFrontend::m_size

m_size can only be 1 or 0 and indicates if the optional has a value. Calling
it 'm_size', giving it a size_t data type and then also comparing indices against
'size' is very confusing. Let's just make this a bool.

Added: 
    

Modified: 
    lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp b/lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp
index e6de525e7d79..c0c819632851 100644
--- a/lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp
+++ b/lldb/source/Plugins/Language/CPlusPlus/LibCxxOptional.cpp
@@ -26,11 +26,12 @@ class OptionalFrontEnd : public SyntheticChildrenFrontEnd {
 
   bool MightHaveChildren() override { return true; }
   bool Update() override;
-  size_t CalculateNumChildren() override { return m_size; }
+  size_t CalculateNumChildren() override { return m_has_value ? 1U : 0U; }
   ValueObjectSP GetChildAtIndex(size_t idx) override;
 
 private:
-  size_t m_size = 0;
+  /// True iff the option contains a value.
+  bool m_has_value = false;
 };
 } // namespace
 
@@ -44,13 +45,13 @@ bool OptionalFrontEnd::Update() {
   // __engaged_ is a bool flag and is true if the optional contains a value.
   // Converting it to unsigned gives us a size of 1 if it contains a value
   // and 0 if not.
-  m_size = engaged_sp->GetValueAsUnsigned(0);
+  m_has_value = engaged_sp->GetValueAsUnsigned(0) == 1;
 
   return false;
 }
 
 ValueObjectSP OptionalFrontEnd::GetChildAtIndex(size_t idx) {
-  if (idx >= m_size)
+  if (!m_has_value)
     return ValueObjectSP();
 
   // __val_ contains the underlying value of an optional if it has one.


        


More information about the lldb-commits mailing list