From 2ee6d55c62e9b62a20b5a87a7665e9836b879120 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 19 Feb 2022 14:49:35 -0500 Subject: [PATCH] Preallocate a buffer in FmtPrinter --- compiler/rustc_middle/src/ty/print/pretty.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 0e94ac40ff7..80ba7232a4a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1583,7 +1583,9 @@ impl<'a, 'tcx> FmtPrinter<'a, 'tcx> { pub fn new(tcx: TyCtxt<'tcx>, ns: Namespace) -> Self { FmtPrinter(Box::new(FmtPrinterData { tcx, - fmt: String::new(), + // Estimated reasonable capacity to allocate upfront based on a few + // benchmarks. + fmt: String::with_capacity(64), empty_path: false, in_value: ns == Namespace::ValueNS, print_alloc_ids: false,