forked from OSchip/llvm-project
[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.
This commit is contained in:
parent
d0c4d4fe09
commit
2a3ef377ec
|
@ -26,11 +26,12 @@ public:
|
||||||
|
|
||||||
bool MightHaveChildren() override { return true; }
|
bool MightHaveChildren() override { return true; }
|
||||||
bool Update() override;
|
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;
|
ValueObjectSP GetChildAtIndex(size_t idx) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_size = 0;
|
/// True iff the option contains a value.
|
||||||
|
bool m_has_value = false;
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -44,13 +45,13 @@ bool OptionalFrontEnd::Update() {
|
||||||
// __engaged_ is a bool flag and is true if the optional contains a value.
|
// __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
|
// Converting it to unsigned gives us a size of 1 if it contains a value
|
||||||
// and 0 if not.
|
// and 0 if not.
|
||||||
m_size = engaged_sp->GetValueAsUnsigned(0);
|
m_has_value = engaged_sp->GetValueAsUnsigned(0) == 1;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueObjectSP OptionalFrontEnd::GetChildAtIndex(size_t idx) {
|
ValueObjectSP OptionalFrontEnd::GetChildAtIndex(size_t idx) {
|
||||||
if (idx >= m_size)
|
if (!m_has_value)
|
||||||
return ValueObjectSP();
|
return ValueObjectSP();
|
||||||
|
|
||||||
// __val_ contains the underlying value of an optional if it has one.
|
// __val_ contains the underlying value of an optional if it has one.
|
||||||
|
|
Loading…
Reference in New Issue