AK: Use kfree_sized() in AK::StringImpl

This commit is contained in:
Andreas Kling 2021-07-11 13:23:13 +02:00
parent 3aabace9f5
commit c68c3fa69c
Notes: sideshowbarker 2024-07-18 09:20:14 +09:00
2 changed files with 8 additions and 6 deletions

View File

@ -37,11 +37,6 @@ StringImpl::~StringImpl()
FlyString::did_destroy_impl({}, *this); FlyString::did_destroy_impl({}, *this);
} }
static inline size_t allocation_size_for_stringimpl(size_t length)
{
return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char);
}
NonnullRefPtr<StringImpl> StringImpl::create_uninitialized(size_t length, char*& buffer) NonnullRefPtr<StringImpl> StringImpl::create_uninitialized(size_t length, char*& buffer)
{ {
VERIFY(length); VERIFY(length);

View File

@ -20,6 +20,8 @@ enum ShouldChomp {
Chomp Chomp
}; };
size_t allocation_size_for_stringimpl(size_t length);
class StringImpl : public RefCounted<StringImpl> { class StringImpl : public RefCounted<StringImpl> {
public: public:
static NonnullRefPtr<StringImpl> create_uninitialized(size_t length, char*& buffer); static NonnullRefPtr<StringImpl> create_uninitialized(size_t length, char*& buffer);
@ -34,7 +36,7 @@ public:
void operator delete(void* ptr) void operator delete(void* ptr)
{ {
kfree(ptr); kfree_sized(ptr, allocation_size_for_stringimpl(static_cast<StringImpl*>(ptr)->m_length));
} }
static StringImpl& the_empty_stringimpl(); static StringImpl& the_empty_stringimpl();
@ -100,6 +102,11 @@ private:
char m_inline_buffer[0]; char m_inline_buffer[0];
}; };
inline size_t allocation_size_for_stringimpl(size_t length)
{
return sizeof(StringImpl) + (sizeof(char) * length) + sizeof(char);
}
template<> template<>
struct Formatter<StringImpl> : Formatter<StringView> { struct Formatter<StringImpl> : Formatter<StringView> {
void format(FormatBuilder& builder, const StringImpl& value) void format(FormatBuilder& builder, const StringImpl& value)