[Lldb-commits] [PATCH] D32306: Remove lock from ConstString::GetLength

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 28 05:21:26 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL301642: Remove lock from ConstString::GetLength (authored by labath).

Changed prior to commit:
  https://reviews.llvm.org/D32306?vs=96841&id=97083#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32306

Files:
  lldb/trunk/source/Utility/ConstString.cpp


Index: lldb/trunk/source/Utility/ConstString.cpp
===================================================================
--- lldb/trunk/source/Utility/ConstString.cpp
+++ lldb/trunk/source/Utility/ConstString.cpp
@@ -38,14 +38,13 @@
 
   static StringPoolEntryType &
   GetStringMapEntryFromKeyData(const char *keyData) {
-    char *ptr = const_cast<char *>(keyData) - sizeof(StringPoolEntryType);
-    return *reinterpret_cast<StringPoolEntryType *>(ptr);
+    return StringPoolEntryType::GetStringMapEntryFromKeyData(keyData);
   }
 
-  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 +217,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 +237,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 +252,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 +265,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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32306.97083.patch
Type: text/x-patch
Size: 2813 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170428/4e915632/attachment.bin>


More information about the lldb-commits mailing list