diff options
| author | Maxime Coste <mawww@kakoune.org> | 2024-02-28 19:00:51 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-02-28 19:02:29 +1100 |
| commit | 3d5a0c672e6f3cf87944b33712e17531aa42c607 (patch) | |
| tree | d402461b8d6517072b27e653d1201888366718a8 /src/shared_string.cc | |
| parent | 57b794ede3cae1e7c21309869a2c617481a55acf (diff) | |
Templatize StringData::create
This improves performance by letting the compiler optimize most use
cases where string count and length are known are compile time.
Diffstat (limited to 'src/shared_string.cc')
| -rw-r--r-- | src/shared_string.cc | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/src/shared_string.cc b/src/shared_string.cc index 862277bd..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); |
