From 844c8f1ec4bfae6ee51fc70b9b6ebb0a4cd894ff Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 5 Oct 2014 10:20:50 +0100 Subject: InternedStrings know their slots --- src/interned_string.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/interned_string.cc') diff --git a/src/interned_string.cc b/src/interned_string.cc index b8825f66..5afb460e 100644 --- a/src/interned_string.cc +++ b/src/interned_string.cc @@ -24,26 +24,32 @@ InternedString StringRegistry::acquire(StringView str) StringView storage_view{m_storage[slot].first.data(), (int)m_storage[slot].first.size()}; m_slot_map[storage_view] = slot; - return InternedString{storage_view, InternedString::AlreadyAcquired{}}; + return InternedString{storage_view, slot}; } size_t slot = it->second; m_storage[slot].second++; StringView storage_view{m_storage[slot].first.data(), (int)m_storage[slot].first.size()}; - return InternedString{storage_view, InternedString::AlreadyAcquired{}}; + return InternedString{storage_view, slot}; } -void StringRegistry::release(StringView str) +void StringRegistry::acquire(size_t slot) { - auto it = m_slot_map.find(str); - kak_assert(it != m_slot_map.end()); + kak_assert(slot < m_storage.size()); + kak_assert(m_storage[slot].second > 0); + ++m_storage[slot].second; +} - size_t slot = it->second; +void StringRegistry::release(size_t slot) +{ if (--m_storage[slot].second == 0) { m_free_slots.push_back(slot); + std::vector& data = m_storage[slot].first; + auto it = m_slot_map.find(StringView{data.data(), (int)data.size()}); + kak_assert(it != m_slot_map.end()); m_slot_map.erase(it); - m_storage[slot].first.clear(); + data.clear(); } } -- cgit v1.2.3