From 3d5a0c672e6f3cf87944b33712e17531aa42c607 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 28 Feb 2024 19:00:51 +1100 Subject: Templatize StringData::create This improves performance by letting the compiler optimize most use cases where string count and length are known are compile time. --- src/shared_string.cc | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'src/shared_string.cc') 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 - namespace Kakoune { -StringDataPtr StringData::create(ArrayView 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(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{res}; -} - StringDataPtr StringData::Registry::intern(StringView str, size_t hash) { kak_assert(hash_value(str) == hash); -- cgit v1.2.3