use more efficient code to generate repeated string

see https://rust.godbolt.org/z/z9vrFP for comparison
This commit is contained in:
Lzu Tao 2019-11-19 23:08:50 +07:00
parent b4f1769734
commit 4da0da9281

View File

@ -154,7 +154,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
if let LitKind::Str(ref lit_content, style) = lit.node {
let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#);
let expanded = if let StrStyle::Raw(n) = style {
let term = (0..n).map(|_| '#').collect::<String>();
let term = "#".repeat(n as usize);
format!("r{0}\"{1}\"{0}", term, lit_content.as_str())
} else {
format!("\"{}\"", lit_content.as_str())