summaryrefslogtreecommitdiff
path: root/src/interned_string.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-10-05 10:20:50 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-10-05 10:20:50 +0100
commit844c8f1ec4bfae6ee51fc70b9b6ebb0a4cd894ff (patch)
tree7477f42ac2f27a15ecd409b097cceb6fa37581a3 /src/interned_string.cc
parentd4a84125ef4d23f2c3e0b2eed5f6efbdc88af141 (diff)
InternedStrings know their slots
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();
}
}