Commit 2a3ef377 authored by Raphael Isemann's avatar Raphael Isemann
Browse files

[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.
parent d0c4d4fe
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -26,11 +26,12 @@ public:

  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.