From 502a1f39ef2336a700cd9d6d9b523c2c7104bdae Mon Sep 17 00:00:00 2001 From: Michael Schubart Date: Tue, 10 Oct 2023 17:20:54 +0100 Subject: [PATCH] Stop building unnecessary string --- crates/toml_edit/src/encode.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/toml_edit/src/encode.rs b/crates/toml_edit/src/encode.rs index 3e984485..db10e29e 100644 --- a/crates/toml_edit/src/encode.rs +++ b/crates/toml_edit/src/encode.rs @@ -455,16 +455,13 @@ impl StringStyle { } fn infer_style(value: &str) -> (StringStyle, bool) { - // For doing pretty prints we store in a new String - // because there are too many cases where pretty cannot - // work. We need to determine: + // We need to determine: // - if we are a "multi-line" pretty (if there are \n) // - if ['''] appears if multi or ['] if single // - if there are any invalid control characters // // Doing it any other way would require multiple passes // to determine if a pretty string works or not. - let mut out = String::with_capacity(value.len() * 2); let mut ty = StringStyle::OnelineSingle; // found consecutive single quotes let mut max_found_singles = 0; @@ -496,7 +493,6 @@ fn infer_style(value: &str) -> (StringStyle, bool) { c if c <= '\u{1f}' || c == '\u{7f}' => can_be_pretty = false, _ => {} } - out.push(ch); } else { // the string cannot be represented as pretty, // still check if it should be multiline