From 53ab564ecfc93984ded8cce26d210af9f828a49c Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Thu, 5 Jan 2023 21:20:32 +0300 Subject: [PATCH] [NFC][YAMLTraits] Use `SmallString<>`+SSO when yamlizing non-strings This gets rid of basically all temporary allocations during YAML serialization of llvm-exegesis snippets, we go from ~1.8M temporary allocations to 13k. --- llvm/include/llvm/Support/YAMLTraits.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/Support/YAMLTraits.h b/llvm/include/llvm/Support/YAMLTraits.h index e46442d..ef74f38 100644 --- a/llvm/include/llvm/Support/YAMLTraits.h +++ b/llvm/include/llvm/Support/YAMLTraits.h @@ -1000,8 +1000,8 @@ template std::enable_if_t::value, void> yamlize(IO &io, T &Val, bool, EmptyContext &Ctx) { if ( io.outputting() ) { - std::string Storage; - raw_string_ostream Buffer(Storage); + SmallString<128> Storage; + raw_svector_ostream Buffer(Storage); ScalarTraits::output(Val, io.getContext(), Buffer); StringRef Str = Buffer.str(); io.scalarString(Str, ScalarTraits::mustQuote(Str)); -- 2.7.4