From 2902fce437911cd728a92c6ba7f754183f8dfb33 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 16 Apr 2015 12:38:59 +0100 Subject: [PATCH] Use an UnorderedSet for string registry --- src/shared_string.cc | 12 ++++++------ src/shared_string.hh | 2 +- src/unordered_map.hh | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/shared_string.cc b/src/shared_string.cc index 1d0cb5a9..2aec6920 100644 --- a/src/shared_string.cc +++ b/src/shared_string.cc @@ -6,20 +6,20 @@ namespace Kakoune SharedString StringRegistry::intern(StringView str) { - auto it = m_strings.find(str); + auto it = m_strings.find({str, SharedString::NoCopy{}}); if (it == m_strings.end()) { SharedString shared_str = str; - it = m_strings.emplace(shared_str, shared_str.m_storage).first; + it = m_strings.emplace(shared_str).first; } - return SharedString{it->second}; + return *it; } void StringRegistry::purge_unused() { for (auto it = m_strings.begin(); it != m_strings.end(); ) { - if (it->second->refcount == 1) + if (it->m_storage->refcount == 1) it = m_strings.erase(it); else ++it; @@ -34,8 +34,8 @@ void StringRegistry::debug_stats() const size_t count = m_strings.size(); for (auto& st : m_strings) { - total_refcount += st.second->refcount - 1; - total_size += (int)st.second->length; + total_refcount += st.m_storage->refcount - 1; + total_size += (int)st.m_storage->length; } write_debug(format(" data size: {}, mean: {}", total_size, (float)total_size/count)); write_debug(format(" refcounts: {}, mean: {}", total_refcount, (float)total_refcount/count)); diff --git a/src/shared_string.hh b/src/shared_string.hh index 5c531ebd..c5de1747 100644 --- a/src/shared_string.hh +++ b/src/shared_string.hh @@ -109,7 +109,7 @@ public: void purge_unused(); private: - UnorderedMap m_strings; + UnorderedSet m_strings; }; inline SharedString intern(StringView str) diff --git a/src/unordered_map.hh b/src/unordered_map.hh index 13246fac..822017fe 100644 --- a/src/unordered_map.hh +++ b/src/unordered_map.hh @@ -5,6 +5,7 @@ #include "memory.hh" #include +#include namespace Kakoune { @@ -13,6 +14,10 @@ template::do using UnorderedMap = std::unordered_map, std::equal_to, Allocator, domain>>; +template::domain()> +using UnorderedSet = std::unordered_set, std::equal_to, + Allocator>; + } #endif // unordered_map_hh_INCLUDED