scott.smith created this revision. ConstStrings are immutable, so there is no need to grab even a reader lock in order to read the length field.
Repository: rL LLVM https://reviews.llvm.org/D32306 Files: source/Utility/ConstString.cpp Index: source/Utility/ConstString.cpp =================================================================== --- source/Utility/ConstString.cpp +++ source/Utility/ConstString.cpp @@ -42,10 +42,10 @@ return *reinterpret_cast<StringPoolEntryType *>(ptr); } - size_t GetConstCStringLength(const char *ccstr) const { + static size_t GetConstCStringLength(const char *ccstr) { if (ccstr != nullptr) { - const uint8_t h = hash(llvm::StringRef(ccstr)); - llvm::sys::SmartScopedReader<false> rlock(m_string_pools[h].m_mutex); + // Since the entry is read only, and we derive the entry entirely from the + // pointer, we don't need the lock. const StringPoolEntryType &entry = GetStringMapEntryFromKeyData(ccstr); return entry.getKey().size(); } @@ -218,10 +218,8 @@ if (m_string == rhs.m_string) return false; - llvm::StringRef lhs_string_ref(m_string, - StringPool().GetConstCStringLength(m_string)); - llvm::StringRef rhs_string_ref( - rhs.m_string, StringPool().GetConstCStringLength(rhs.m_string)); + llvm::StringRef lhs_string_ref(GetStringRef()); + llvm::StringRef rhs_string_ref(rhs.GetStringRef()); // If both have valid C strings, then return the comparison if (lhs_string_ref.data() && rhs_string_ref.data()) @@ -240,7 +238,7 @@ } size_t ConstString::GetLength() const { - return StringPool().GetConstCStringLength(m_string); + return Pool::GetConstCStringLength(m_string); } bool ConstString::Equals(const ConstString &lhs, const ConstString &rhs, @@ -255,10 +253,8 @@ return false; // perform case insensitive equality test - llvm::StringRef lhs_string_ref( - lhs.m_string, StringPool().GetConstCStringLength(lhs.m_string)); - llvm::StringRef rhs_string_ref( - rhs.m_string, StringPool().GetConstCStringLength(rhs.m_string)); + llvm::StringRef lhs_string_ref(lhs.GetStringRef()); + llvm::StringRef rhs_string_ref(rhs.GetStringRef()); return lhs_string_ref.equals_lower(rhs_string_ref); } @@ -270,10 +266,8 @@ if (lhs_cstr == rhs_cstr) return 0; if (lhs_cstr && rhs_cstr) { - llvm::StringRef lhs_string_ref( - lhs_cstr, StringPool().GetConstCStringLength(lhs_cstr)); - llvm::StringRef rhs_string_ref( - rhs_cstr, StringPool().GetConstCStringLength(rhs_cstr)); + llvm::StringRef lhs_string_ref(lhs.GetStringRef()); + llvm::StringRef rhs_string_ref(rhs.GetStringRef()); if (case_sensitive) { return lhs_string_ref.compare(rhs_string_ref);
Index: source/Utility/ConstString.cpp =================================================================== --- source/Utility/ConstString.cpp +++ source/Utility/ConstString.cpp @@ -42,10 +42,10 @@ return *reinterpret_cast<StringPoolEntryType *>(ptr); } - size_t GetConstCStringLength(const char *ccstr) const { + static size_t GetConstCStringLength(const char *ccstr) { if (ccstr != nullptr) { - const uint8_t h = hash(llvm::StringRef(ccstr)); - llvm::sys::SmartScopedReader<false> rlock(m_string_pools[h].m_mutex); + // Since the entry is read only, and we derive the entry entirely from the + // pointer, we don't need the lock. const StringPoolEntryType &entry = GetStringMapEntryFromKeyData(ccstr); return entry.getKey().size(); } @@ -218,10 +218,8 @@ if (m_string == rhs.m_string) return false; - llvm::StringRef lhs_string_ref(m_string, - StringPool().GetConstCStringLength(m_string)); - llvm::StringRef rhs_string_ref( - rhs.m_string, StringPool().GetConstCStringLength(rhs.m_string)); + llvm::StringRef lhs_string_ref(GetStringRef()); + llvm::StringRef rhs_string_ref(rhs.GetStringRef()); // If both have valid C strings, then return the comparison if (lhs_string_ref.data() && rhs_string_ref.data()) @@ -240,7 +238,7 @@ } size_t ConstString::GetLength() const { - return StringPool().GetConstCStringLength(m_string); + return Pool::GetConstCStringLength(m_string); } bool ConstString::Equals(const ConstString &lhs, const ConstString &rhs, @@ -255,10 +253,8 @@ return false; // perform case insensitive equality test - llvm::StringRef lhs_string_ref( - lhs.m_string, StringPool().GetConstCStringLength(lhs.m_string)); - llvm::StringRef rhs_string_ref( - rhs.m_string, StringPool().GetConstCStringLength(rhs.m_string)); + llvm::StringRef lhs_string_ref(lhs.GetStringRef()); + llvm::StringRef rhs_string_ref(rhs.GetStringRef()); return lhs_string_ref.equals_lower(rhs_string_ref); } @@ -270,10 +266,8 @@ if (lhs_cstr == rhs_cstr) return 0; if (lhs_cstr && rhs_cstr) { - llvm::StringRef lhs_string_ref( - lhs_cstr, StringPool().GetConstCStringLength(lhs_cstr)); - llvm::StringRef rhs_string_ref( - rhs_cstr, StringPool().GetConstCStringLength(rhs_cstr)); + llvm::StringRef lhs_string_ref(lhs.GetStringRef()); + llvm::StringRef rhs_string_ref(rhs.GetStringRef()); if (case_sensitive) { return lhs_string_ref.compare(rhs_string_ref);
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits