[PATCH] D50327: Add ConstString::IsNull() to tell between null vs. empty strings and fix usage in Mangled::GetDemangledName()
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 6 07:15:58 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339014: Add ConstString::IsNull() to tell between null vs. empty strings and fix usageā¦ (authored by stefan.graenitz, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D50327?vs=159278&id=159297#toc
Repository:
rL LLVM
https://reviews.llvm.org/D50327
Files:
lldb/trunk/include/lldb/Utility/ConstString.h
lldb/trunk/source/Core/Mangled.cpp
lldb/trunk/unittests/Utility/ConstStringTest.cpp
Index: lldb/trunk/include/lldb/Utility/ConstString.h
===================================================================
--- lldb/trunk/include/lldb/Utility/ConstString.h
+++ lldb/trunk/include/lldb/Utility/ConstString.h
@@ -346,6 +346,15 @@
bool IsEmpty() const { return m_string == nullptr || m_string[0] == '\0'; }
//------------------------------------------------------------------
+ /// Test for null string.
+ ///
+ /// @return
+ /// @li \b true if there is no string associated with this instance.
+ /// @li \b false if there is a string associated with this instance.
+ //------------------------------------------------------------------
+ bool IsNull() const { return m_string == nullptr; }
+
+ //------------------------------------------------------------------
/// Set the C string value.
///
/// Set the string value in the object by uniquing the \a cstr string value
Index: lldb/trunk/unittests/Utility/ConstStringTest.cpp
===================================================================
--- lldb/trunk/unittests/Utility/ConstStringTest.cpp
+++ lldb/trunk/unittests/Utility/ConstStringTest.cpp
@@ -33,3 +33,20 @@
EXPECT_TRUE(foo.GetMangledCounterpart(counterpart));
EXPECT_EQ("bar", counterpart.GetStringRef());
}
+
+TEST(ConstStringTest, NullAndEmptyStates) {
+ ConstString foo("foo");
+ EXPECT_FALSE(!foo);
+ EXPECT_FALSE(foo.IsEmpty());
+ EXPECT_FALSE(foo.IsNull());
+
+ ConstString empty("");
+ EXPECT_TRUE(!empty);
+ EXPECT_TRUE(empty.IsEmpty());
+ EXPECT_FALSE(empty.IsNull());
+
+ ConstString null;
+ EXPECT_TRUE(!null);
+ EXPECT_TRUE(null.IsEmpty());
+ EXPECT_TRUE(null.IsNull());
+}
Index: lldb/trunk/source/Core/Mangled.cpp
===================================================================
--- lldb/trunk/source/Core/Mangled.cpp
+++ lldb/trunk/source/Core/Mangled.cpp
@@ -242,7 +242,7 @@
Mangled::GetDemangledName(lldb::LanguageType language) const {
// Check to make sure we have a valid mangled name and that we haven't
// already decoded our mangled name.
- if (m_mangled && !m_demangled) {
+ if (m_mangled && m_demangled.IsNull()) {
// We need to generate and cache the demangled name.
static Timer::Category func_cat(LLVM_PRETTY_FUNCTION);
Timer scoped_timer(func_cat, "Mangled::GetDemangledName (m_mangled = %s)",
@@ -312,7 +312,7 @@
free(demangled_name);
}
}
- if (!m_demangled) {
+ if (m_demangled.IsNull()) {
// Set the demangled string to the empty string to indicate we tried to
// parse it once and failed.
m_demangled.SetCString("");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50327.159297.patch
Type: text/x-patch
Size: 2602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180806/6ad2f490/attachment.bin>
More information about the llvm-commits
mailing list