about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2023-11-26 18:44:16 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2023-11-26 18:44:16 -0500
commit8375fe4710e7f6a0a27770e4c6c5df4317e9bb2f (patch)
tree5d3e84cbfcef75dd6a5718d84654480670f21697
parent1bcbb7c93b96828092e83e52d592faa046183d6c (diff)
downloadrust-8375fe4710e7f6a0a27770e4c6c5df4317e9bb2f.tar.gz
rust-8375fe4710e7f6a0a27770e4c6c5df4317e9bb2f.zip
Simplify indenting in THIR printing
This cuts >100kb from a local librustc_driver.so build, and seems just
obviously simpler.
-rw-r--r--compiler/rustc_mir_build/src/thir/print.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_mir_build/src/thir/print.rs b/compiler/rustc_mir_build/src/thir/print.rs
index c3b2309b7cd..e449928a643 100644
--- a/compiler/rustc_mir_build/src/thir/print.rs
+++ b/compiler/rustc_mir_build/src/thir/print.rs
@@ -31,8 +31,8 @@ const INDENT: &str = "    ";
 
 macro_rules! print_indented {
     ($writer:ident, $s:expr, $indent_lvl:expr) => {
-        let indent = (0..$indent_lvl).map(|_| INDENT).collect::<Vec<_>>().concat();
-        writeln!($writer, "{}{}", indent, $s).expect("unable to write to ThirPrinter");
+        $writer.indent($indent_lvl);
+        writeln!($writer, "{}", $s).expect("unable to write to ThirPrinter");
     };
 }
 
@@ -48,6 +48,12 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
         Self { thir, fmt: String::new() }
     }
 
+    fn indent(&mut self, level: usize) {
+        for _ in 0..level {
+            self.fmt.push_str(INDENT);
+        }
+    }
+
     fn print(&mut self) {
         print_indented!(self, "params: [", 0);
         for param in self.thir.params.iter() {