summaryrefslogtreecommitdiff
path: root/source/Utility/ConstString.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Utility/ConstString.cpp')
-rw-r--r--source/Utility/ConstString.cpp66
1 files changed, 31 insertions, 35 deletions
diff --git a/source/Utility/ConstString.cpp b/source/Utility/ConstString.cpp
index 5ef4b2faa3b8..9b8bea71e2ad 100644
--- a/source/Utility/ConstString.cpp
+++ b/source/Utility/ConstString.cpp
@@ -12,20 +12,20 @@
#include "lldb/Utility/Stream.h"
#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/iterator.h" // for iterator_facade_base
-#include "llvm/Support/Allocator.h" // for BumpPtrAllocator
-#include "llvm/Support/DJB.h" // for djbHash
-#include "llvm/Support/FormatProviders.h" // for format_provider
+#include "llvm/ADT/iterator.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/DJB.h"
+#include "llvm/Support/FormatProviders.h"
#include "llvm/Support/RWMutex.h"
#include "llvm/Support/Threading.h"
-#include <algorithm> // for min
+#include <algorithm>
#include <array>
-#include <utility> // for make_pair, pair
+#include <utility>
-#include <inttypes.h> // for PRIu64
-#include <stdint.h> // for uint8_t, uint32_t, uint64_t
-#include <string.h> // for size_t, strlen
+#include <inttypes.h>
+#include <stdint.h>
+#include <string.h>
using namespace lldb_private;
@@ -111,38 +111,34 @@ public:
}
const char *
- GetConstCStringAndSetMangledCounterPart(const char *demangled_cstr,
+ GetConstCStringAndSetMangledCounterPart(llvm::StringRef demangled,
const char *mangled_ccstr) {
- if (demangled_cstr != nullptr) {
- const char *demangled_ccstr = nullptr;
+ const char *demangled_ccstr = nullptr;
- {
- llvm::StringRef string_ref(demangled_cstr);
- const uint8_t h = hash(string_ref);
- llvm::sys::SmartScopedWriter<false> wlock(m_string_pools[h].m_mutex);
+ {
+ const uint8_t h = hash(demangled);
+ llvm::sys::SmartScopedWriter<false> wlock(m_string_pools[h].m_mutex);
- // Make string pool entry with the mangled counterpart already set
- StringPoolEntryType &entry =
- *m_string_pools[h]
- .m_string_map.insert(std::make_pair(string_ref, mangled_ccstr))
- .first;
+ // Make or update string pool entry with the mangled counterpart
+ StringPool &map = m_string_pools[h].m_string_map;
+ StringPoolEntryType &entry = *map.try_emplace(demangled).first;
- // Extract the const version of the demangled_cstr
- demangled_ccstr = entry.getKeyData();
- }
+ entry.second = mangled_ccstr;
- {
- // Now assign the demangled const string as the counterpart of the
- // mangled const string...
- const uint8_t h = hash(llvm::StringRef(mangled_ccstr));
- llvm::sys::SmartScopedWriter<false> wlock(m_string_pools[h].m_mutex);
- GetStringMapEntryFromKeyData(mangled_ccstr).setValue(demangled_ccstr);
- }
+ // Extract the const version of the demangled_cstr
+ demangled_ccstr = entry.getKeyData();
+ }
- // Return the constant demangled C string
- return demangled_ccstr;
+ {
+ // Now assign the demangled const string as the counterpart of the
+ // mangled const string...
+ const uint8_t h = hash(llvm::StringRef(mangled_ccstr));
+ llvm::sys::SmartScopedWriter<false> wlock(m_string_pools[h].m_mutex);
+ GetStringMapEntryFromKeyData(mangled_ccstr).setValue(demangled_ccstr);
}
- return nullptr;
+
+ // Return the constant demangled C string
+ return demangled_ccstr;
}
const char *GetConstTrimmedCStringWithLength(const char *cstr,
@@ -306,7 +302,7 @@ void ConstString::SetString(const llvm::StringRef &s) {
m_string = StringPool().GetConstCStringWithLength(s.data(), s.size());
}
-void ConstString::SetCStringWithMangledCounterpart(const char *demangled,
+void ConstString::SetStringWithMangledCounterpart(llvm::StringRef demangled,
const ConstString &mangled) {
m_string = StringPool().GetConstCStringAndSetMangledCounterPart(
demangled, mangled.m_string);