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<unsigned int>(...)
JsonObjectSerializer<Kernel::KBufferBuilder>::add(..., unsigned int)
Kernel::procfs$all(Kernel::InodeIdentifier, ...) const
Kernel::procfs$all(Kernel::InodeIdentifier, Kernel::KBufferBuilder&)
This commit is contained in:
Gunnar Beutner 2021-05-12 21:40:29 +02:00 committed by Andreas Kling
parent 1bb20a255f
commit 93c3b6bdd2
Notes: sideshowbarker 2024-07-18 18:16:21 +09:00

View File

@ -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();