From b3acb348d953e56c17e039f2e668cfd08dd817ab Mon Sep 17 00:00:00 2001 From: Jonathan Tran Date: Fri, 7 Feb 2025 16:34:33 -0500 Subject: [PATCH] Change to not allocate extra String --- src/wasm-lib/kcl/src/unparser.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/wasm-lib/kcl/src/unparser.rs b/src/wasm-lib/kcl/src/unparser.rs index 4a378024ce..5b43e73dd9 100644 --- a/src/wasm-lib/kcl/src/unparser.rs +++ b/src/wasm-lib/kcl/src/unparser.rs @@ -16,23 +16,16 @@ impl Program { pub fn recast(&self, options: &FormatOptions, indentation_level: usize) -> String { let indentation = options.get_indentation(indentation_level); - let result = self + let mut result = self .shebang .as_ref() .map(|sh| format!("{}\n\n", sh.inner.content)) .unwrap_or_default(); - let result = if !self.non_code_meta.start_nodes.is_empty() { - result - + &self - .non_code_meta - .start_nodes - .iter() - .map(|start| start.recast(options, indentation_level)) - .collect::() - } else { - result - }; + for start in &self.non_code_meta.start_nodes { + result.push_str(&start.recast(options, indentation_level)); + } + let result = result; // Remove mutation. let result = self .body