diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2015-01-15 13:54:38 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2015-01-15 19:26:38 +0000 |
| commit | 76d806e98d5e80f7f0c233d561371b89b8724c23 (patch) | |
| tree | fa93543d091e89045c04766ce7854d3f125ab3dd /src/interned_string.cc | |
| parent | 2a878d51fdfe5832a3b979dbc8e5b2144ad0d1f3 (diff) | |
Replace InternedStrings with SharedString, shared_ptr based
Diffstat (limited to 'src/interned_string.cc')
| -rw-r--r-- | src/interned_string.cc | 78 |
1 files changed, 0 insertions, 78 deletions
diff --git a/src/interned_string.cc b/src/interned_string.cc deleted file mode 100644 index 0755e3d4..00000000 --- a/src/interned_string.cc +++ /dev/null @@ -1,78 +0,0 @@ -#include "interned_string.hh" -#include "debug.hh" - -namespace Kakoune -{ - -void StringRegistry::debug_stats() const -{ - write_debug("Interned Strings stats:"); - write_debug(" slots: " + to_string(m_storage.size()) + " allocated, " + to_string(m_free_slots.size()) + " free"); - size_t total_refcount = 0; - size_t total_size = 0; - size_t count = 0; - for (auto& st : m_storage) - { - if (st.refcount == 0) - continue; - total_refcount += st.refcount; - total_size += st.data.size(); - ++count; - } - write_debug(" data size: " + to_string(total_size) + ", mean: " + to_string((float)total_size/count)); - write_debug(" refcounts: " + to_string(total_refcount) + ", mean: " + to_string((float)total_refcount/count)); -} - -InternedString StringRegistry::acquire(StringView str) -{ - auto it = m_slot_map.find(str); - if (it == m_slot_map.end()) - { - Slot slot; - if (not m_free_slots.empty()) - { - slot = m_free_slots.back(); - m_free_slots.pop_back(); - 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({{str.begin(), str.end()}, 1}); - } - // Create a new string view that point to the storage data - 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}; - } - - Slot slot = it->second; - auto& data = m_storage[slot]; - ++data.refcount; - return {{data.data.data(), (int)data.data.size()}, 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(Slot slot) noexcept -{ - kak_assert(m_storage[slot].refcount > 0); - if (--m_storage[slot].refcount == 0) - { - m_free_slots.push_back(slot); - auto& 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); - data = Vector<char, MemoryDomain::InternedString>{}; - } -} - -} |
