summaryrefslogtreecommitdiff
path: root/src/shared_string.hh
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2024-02-28 21:48:58 +1100
committerMaxime Coste <mawww@kakoune.org>2024-02-28 21:48:58 +1100
commit74ce9f3cfeeef074eb821f85e39fa38c644c9df6 (patch)
tree4658fba408e07da795a7bd27b12b5124a1cb0b11 /src/shared_string.hh
parentb8a151ab46cc873a36f6c44e61842e5db3f523ca (diff)
Fix missing destructor call and simplify code slightly
Although the destructor call is a no-op, it is more correct to have it to ensure the compiler knows the lifetime of that object ended.
Diffstat (limited to 'src/shared_string.hh')
-rw-r--r--src/shared_string.hh8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/shared_string.hh b/src/shared_string.hh
index bb06c7fc..78e9fef4 100644
--- a/src/shared_string.hh
+++ b/src/shared_string.hh
@@ -37,7 +37,9 @@ private:
return;
if (r->refcount & interned_flag)
Registry::instance().remove(r->strview());
- StringData::operator delete(r, sizeof(StringData) + r->length + 1);
+ auto alloc_len = sizeof(StringData) + r->length + 1;
+ r->~StringData();
+ operator delete(r, alloc_len);
}
static void ptr_moved(StringData*, void*, void*) noexcept {}
};
@@ -60,11 +62,11 @@ public:
static Ptr create(ConvertibleTo<StringView> auto&&... strs)
{
const int len = ((int)StringView{strs}.length() + ...);
- void* ptr = StringData::operator new(sizeof(StringData) + len + 1);
+ void* ptr = operator new(sizeof(StringData) + len + 1);
auto* res = new (ptr) StringData(len);
auto* data = reinterpret_cast<char*>(res + 1);
auto append = [&](StringView str) {
- if (str.empty()) // memccpy(..., nullptr, 0) is UB
+ if (str.empty()) // memcpy(..., nullptr, 0) is UB
return;
memcpy(data, str.begin(), (size_t)str.length());
data += (int)str.length();