diff options
| author | Igor Ramazanov <igor.ramazanov@protonmail.com> | 2024-06-04 23:19:47 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-04 23:19:47 +0200 |
| commit | 4d21fbb3b0b66ef48270e5655bf2687a1f78becf (patch) | |
| tree | 479c9ca7cd6e9fcf16d7abc7ebea8c8fe0b502e9 /src/shared_string.cc | |
| parent | 7e8c430ad0706604c0b919207f322a5c14150575 (diff) | |
| parent | 727d2391c7695056ce6bb170b127c6e6ca9e1ab4 (diff) | |
Merge branch 'mawww:master' into contrib/gendocs.sh
Diffstat (limited to 'src/shared_string.cc')
| -rw-r--r-- | src/shared_string.cc | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/src/shared_string.cc b/src/shared_string.cc index 7291699c..f88008b1 100644 --- a/src/shared_string.cc +++ b/src/shared_string.cc @@ -1,30 +1,9 @@ #include "shared_string.hh" #include "buffer_utils.hh" -#include <cstring> - namespace Kakoune { -StringDataPtr StringData::create(ArrayView<const StringView> strs) -{ - const int len = accumulate(strs, 0, [](int l, StringView s) { - return l + (int)s.length(); - }); - void* ptr = StringData::operator new(sizeof(StringData) + len + 1); - auto* res = new (ptr) StringData(len); - auto* data = reinterpret_cast<char*>(res + 1); - for (auto& str : strs) - { - if (str.length() == 0) // memccpy(..., nullptr, 0) is UB - continue; - memcpy(data, str.begin(), (size_t)str.length()); - data += (int)str.length(); - } - *data = 0; - return RefPtr<StringData, PtrPolicy>{res}; -} - StringDataPtr StringData::Registry::intern(StringView str, size_t hash) { kak_assert(hash_value(str) == hash); @@ -51,15 +30,16 @@ void StringData::Registry::remove(StringView str) void StringData::Registry::debug_stats() const { - write_to_debug_buffer("Shared Strings stats:"); + write_to_debug_buffer("Interned Strings stats:"); + size_t count = m_strings.size(); size_t total_refcount = 0; size_t total_size = 0; - size_t count = m_strings.size(); for (auto& st : m_strings) { - total_refcount += (st.value->refcount & refcount_mask) - 1; + total_refcount += st.value->refcount & refcount_mask; total_size += (int)st.value->length; } + write_to_debug_buffer(format(" count: {}", count)); write_to_debug_buffer(format(" data size: {}, mean: {}", total_size, (float)total_size/count)); write_to_debug_buffer(format(" refcounts: {}, mean: {}", total_refcount, (float)total_refcount/count)); } |
