From 118a6e1a7cb0f9bb386e3130c7ad1f9dbcab6300 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 13 Jan 2015 13:58:11 +0000 Subject: [PATCH] Use uint32_t for interned strings slots --- src/interned_string.cc | 8 ++++---- src/interned_string.hh | 15 +++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/interned_string.cc b/src/interned_string.cc index fb6898c09..0755e3d4d 100644 --- a/src/interned_string.cc +++ b/src/interned_string.cc @@ -28,7 +28,7 @@ InternedString StringRegistry::acquire(StringView str) auto it = m_slot_map.find(str); if (it == m_slot_map.end()) { - size_t slot; + Slot slot; if (not m_free_slots.empty()) { slot = m_free_slots.back(); @@ -48,20 +48,20 @@ InternedString StringRegistry::acquire(StringView str) return InternedString{storage_view, slot}; } - size_t slot = it->second; + Slot slot = it->second; auto& data = m_storage[slot]; ++data.refcount; return {{data.data.data(), (int)data.data.size()}, slot}; } -void StringRegistry::acquire(size_t slot) +void StringRegistry::acquire(Slot slot) { kak_assert(slot < m_storage.size()); kak_assert(m_storage[slot].refcount > 0); ++m_storage[slot].refcount; } -void StringRegistry::release(size_t slot) noexcept +void StringRegistry::release(Slot slot) noexcept { kak_assert(m_storage[slot].refcount > 0); if (--m_storage[slot].refcount == 0) diff --git a/src/interned_string.hh b/src/interned_string.hh index 66c7bd586..b74653b77 100644 --- a/src/interned_string.hh +++ b/src/interned_string.hh @@ -6,6 +6,8 @@ #include "unordered_map.hh" #include "vector.hh" +#include + namespace Kakoune { @@ -17,13 +19,14 @@ public: void debug_stats() const; private: friend class InternedString; + using Slot = uint32_t; InternedString acquire(StringView str); - void acquire(size_t slot); - void release(size_t slot) noexcept; + void acquire(Slot slot); + void release(Slot slot) noexcept; - UnorderedMap m_slot_map; - Vector m_free_slots; + UnorderedMap m_slot_map; + Vector m_free_slots; struct DataAndRefCount { Vector data; @@ -101,7 +104,7 @@ public: private: friend class StringRegistry; - InternedString(StringView str, size_t slot) + InternedString(StringView str, StringRegistry::Slot slot) : StringView(str), m_slot(slot) {} void acquire_ifn(StringView str) @@ -121,7 +124,7 @@ private: StringRegistry::instance().release(m_slot); } - size_t m_slot = -1; + StringRegistry::Slot m_slot = -1; }; inline size_t hash_value(const Kakoune::InternedString& str)