diff --git a/src/interned_string.cc b/src/interned_string.cc index 2f2f56f8..5395cf02 100644 --- a/src/interned_string.cc +++ b/src/interned_string.cc @@ -13,16 +13,16 @@ InternedString StringRegistry::acquire(StringView str) { slot = m_free_slots.back(); m_free_slots.pop_back(); - kak_assert(m_storage[slot].second == 0); - m_storage[slot] = DataAndRefCount({str.begin(), str.end()}, 1); + kak_assert(m_storage[slot].refcount == 0); + m_storage[slot] = DataAndRefCount{{str.begin(), str.end()}, 1}; } else { slot = m_storage.size(); - m_storage.push_back(DataAndRefCount({str.begin(), str.end()}, 1)); + m_storage.push_back({{str.begin(), str.end()}, 1}); } // Create a new string view that point to the storage data - StringView storage_view{m_storage[slot].first.data(), (int)m_storage[slot].first.size()}; + StringView storage_view{m_storage[slot].data.data(), (int)m_storage[slot].data.size()}; m_slot_map[storage_view] = slot; return InternedString{storage_view, slot}; @@ -30,24 +30,24 @@ InternedString StringRegistry::acquire(StringView str) size_t slot = it->second; auto& data = m_storage[slot]; - ++data.second; - return {{data.first.data(), (int)data.first.size()}, slot}; + ++data.refcount; + return {{data.data.data(), (int)data.data.size()}, slot}; } void StringRegistry::acquire(size_t slot) { kak_assert(slot < m_storage.size()); - kak_assert(m_storage[slot].second > 0); - ++m_storage[slot].second; + kak_assert(m_storage[slot].refcount > 0); + ++m_storage[slot].refcount; } void StringRegistry::release(size_t slot) noexcept { - kak_assert(m_storage[slot].second > 0); - if (--m_storage[slot].second == 0) + kak_assert(m_storage[slot].refcount > 0); + if (--m_storage[slot].refcount == 0) { m_free_slots.push_back(slot); - std::vector& data = m_storage[slot].first; + std::vector& data = m_storage[slot].data; auto it = m_slot_map.find(StringView{data.data(), (int)data.size()}); kak_assert(it != m_slot_map.end()); m_slot_map.erase(it); diff --git a/src/interned_string.hh b/src/interned_string.hh index 4afdb157..b96bbfea 100644 --- a/src/interned_string.hh +++ b/src/interned_string.hh @@ -21,7 +21,7 @@ private: UnorderedMap m_slot_map; std::vector m_free_slots; - using DataAndRefCount = std::pair, int>; + struct DataAndRefCount { std::vector data; int refcount; }; std::vector m_storage; };