Skip to content

Commit

Permalink
Change to not allocate extra String
Browse files Browse the repository at this point in the history
  • Loading branch information
jtran committed Feb 7, 2025
1 parent 0aed462 commit b3acb34
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/wasm-lib/kcl/src/unparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>()
} 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
Expand Down

0 comments on commit b3acb34

Please sign in to comment.