]> git.lizzy.rs Git - rust.git/commitdiff
Preallocate a buffer in FmtPrinter
authorMark Rousskov <mark.simulacrum@gmail.com>
Sat, 19 Feb 2022 19:49:35 +0000 (14:49 -0500)
committerMark Rousskov <mark.simulacrum@gmail.com>
Mon, 21 Feb 2022 00:32:19 +0000 (19:32 -0500)
compiler/rustc_middle/src/ty/print/pretty.rs

index 0e94ac40ff7e56791bfde8c009b576ee7a2cb654..80ba7232a4a3d515ef01cb12d39773170d9bbdb4 100644 (file)
@@ -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,