summaryrefslogtreecommitdiff
path: root/src/interned_string.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/interned_string.cc')
-rw-r--r--src/interned_string.cc20
1 files changed, 13 insertions, 7 deletions
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<char>& 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();
}
}