From 93c3b6bdd249f6410f18be782fb12a9451ebf7c7 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 12 May 2021 21:40:29 +0200 Subject: [PATCH] Kernel: Avoid allocations in KBufferBuilder::appendff This avoids some of the the shortest-lived allocations in the kernel: StringImpl::create_uninitialized(unsigned long, char*&) StringImpl::create(char const*, unsigned long, ShouldChomp) StringBuilder::to_string() const String::vformatted(StringView, TypeErasedFormatParams) void Kernel::KBufferBuilder::appendff(...) JsonObjectSerializer::add(..., unsigned int) Kernel::procfs$all(Kernel::InodeIdentifier, ...) const Kernel::procfs$all(Kernel::InodeIdentifier, Kernel::KBufferBuilder&) --- Kernel/KBufferBuilder.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Kernel/KBufferBuilder.h b/Kernel/KBufferBuilder.h index 106d9d9155..4ab6b1527d 100644 --- a/Kernel/KBufferBuilder.h +++ b/Kernel/KBufferBuilder.h @@ -33,7 +33,9 @@ public: { // FIXME: This is really not the way to go about it, but vformat expects a // StringBuilder. Why does this class exist anyways? - append(String::formatted(fmtstr.view(), parameters...)); + StringBuilder builder; + vformat(builder, fmtstr.view(), AK::VariadicFormatParams { parameters... }); + append_bytes(builder.string_view().bytes()); } bool flush();