Skip to content

Commit

Permalink
Eliminate an allocation from Literal::byte_string
Browse files Browse the repository at this point in the history
    error: `format!(..)` appended to existing `String`
       --> src/fallback.rs:879:22
        |
    879 |                 _ => escaped.push_str(&format!("\\x{:02X}", b)),
        |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = note: `-D clippy::format-push-string` implied by `-D clippy::all`
        = help: consider using `write!` to avoid the extra allocation
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
  • Loading branch information
dtolnay committed May 6, 2022
1 parent 4a3502c commit 16c4bb4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{Delimiter, Spacing, TokenTree};
use std::cell::RefCell;
#[cfg(span_locations)]
use std::cmp;
use std::fmt::{self, Debug, Display};
use std::fmt::{self, Debug, Display, Write as _};
use std::iter::FromIterator;
use std::mem;
use std::ops::RangeBounds;
Expand Down Expand Up @@ -876,7 +876,9 @@ impl Literal {
b'"' => escaped.push_str("\\\""),
b'\\' => escaped.push_str("\\\\"),
b'\x20'..=b'\x7E' => escaped.push(*b as char),
_ => escaped.push_str(&format!("\\x{:02X}", b)),
_ => {
let _ = write!(escaped, "\\x{:02X}", b);
}
}
}
escaped.push('"');
Expand Down

0 comments on commit 16c4bb4

Please sign in to comment.