Rollup merge of #4830 - lzutao:str-repeat, r=flip1995
use more efficient code to generate repeated string see https://rust.godbolt.org/z/z9vrFP for comparison changelog: none
This commit is contained in:
commit
b4524004e0
@ -154,7 +154,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
|
|||||||
if let LitKind::Str(ref lit_content, style) = lit.node {
|
if let LitKind::Str(ref lit_content, style) = lit.node {
|
||||||
let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#);
|
let callsite = snippet(cx, args[0].span.source_callsite(), r#""foo""#);
|
||||||
let expanded = if let StrStyle::Raw(n) = style {
|
let expanded = if let StrStyle::Raw(n) = style {
|
||||||
let term = (0..n).map(|_| '#').collect::<String>();
|
let term = "#".repeat(usize::from(n));
|
||||||
format!("r{0}\"{1}\"{0}", term, lit_content.as_str())
|
format!("r{0}\"{1}\"{0}", term, lit_content.as_str())
|
||||||
} else {
|
} else {
|
||||||
format!("\"{}\"", lit_content.as_str())
|
format!("\"{}\"", lit_content.as_str())
|
||||||
|
Loading…
Reference in New Issue
Block a user