瀏覽代碼

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&)
Gunnar Beutner 4 年之前
父節點
當前提交
93c3b6bdd2
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      Kernel/KBufferBuilder.h

+ 3 - 1
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();