Skip to content

Commit

Permalink
Merge pull request #620 from schubart/stop_building_unnecessary_string
Browse files Browse the repository at this point in the history
Stop building unnecessary string
  • Loading branch information
epage authored Oct 10, 2023
2 parents e16bd58 + 502a1f3 commit e597616
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e597616

Please sign in to comment.