Author: Alex Langford Date: 2023-06-05T13:06:58-07:00 New Revision: 8a4636929fd649d4311fadb03c6e4be4fefec3af
URL: https://github.com/llvm/llvm-project/commit/8a4636929fd649d4311fadb03c6e4be4fefec3af DIFF: https://github.com/llvm/llvm-project/commit/8a4636929fd649d4311fadb03c6e4be4fefec3af.diff LOG: [lldb][NFCI] ConstString methods should take StringRefs by value StringRef was made to be passed by value efficiently. Differential Revision: https://reviews.llvm.org/D152010 Added: Modified: lldb/include/lldb/Utility/ConstString.h lldb/source/Utility/ConstString.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/Utility/ConstString.h b/lldb/include/lldb/Utility/ConstString.h index 332cca5fdbf12..c23c6fd3546e5 100644 --- a/lldb/include/lldb/Utility/ConstString.h +++ b/lldb/include/lldb/Utility/ConstString.h @@ -44,7 +44,7 @@ class ConstString { /// Initializes the string to an empty string. ConstString() = default; - explicit ConstString(const llvm::StringRef &s); + explicit ConstString(llvm::StringRef s); /// Construct with C String value /// @@ -328,7 +328,7 @@ class ConstString { /// A NULL terminated C string to add to the string pool. void SetCString(const char *cstr); - void SetString(const llvm::StringRef &s); + void SetString(llvm::StringRef s); /// Set the C string value and its mangled counterpart. /// diff --git a/lldb/source/Utility/ConstString.cpp b/lldb/source/Utility/ConstString.cpp index 7b084769e1ffb..4535771adfb73 100644 --- a/lldb/source/Utility/ConstString.cpp +++ b/lldb/source/Utility/ConstString.cpp @@ -98,7 +98,7 @@ class Pool { return nullptr; } - const char *GetConstCStringWithStringRef(const llvm::StringRef &string_ref) { + const char *GetConstCStringWithStringRef(llvm::StringRef string_ref) { if (string_ref.data()) { const uint8_t h = hash(string_ref); @@ -171,7 +171,7 @@ class Pool { } protected: - uint8_t hash(const llvm::StringRef &s) const { + uint8_t hash(llvm::StringRef s) const { uint32_t h = llvm::djbHash(s); return ((h >> 24) ^ (h >> 16) ^ (h >> 8) ^ h) & 0xff; } @@ -208,7 +208,7 @@ ConstString::ConstString(const char *cstr) ConstString::ConstString(const char *cstr, size_t cstr_len) : m_string(StringPool().GetConstCStringWithLength(cstr, cstr_len)) {} -ConstString::ConstString(const llvm::StringRef &s) +ConstString::ConstString(llvm::StringRef s) : m_string(StringPool().GetConstCStringWithStringRef(s)) {} bool ConstString::operator<(ConstString rhs) const { @@ -302,8 +302,8 @@ void ConstString::SetCString(const char *cstr) { m_string = StringPool().GetConstCString(cstr); } -void ConstString::SetString(const llvm::StringRef &s) { - m_string = StringPool().GetConstCStringWithLength(s.data(), s.size()); +void ConstString::SetString(llvm::StringRef s) { + m_string = StringPool().GetConstCStringWithStringRef(s); } void ConstString::SetStringWithMangledCounterpart(llvm::StringRef demangled, _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits