Skip to content

Commit e3a4a03

Browse files
committed
Use str::repeat
1 parent 09940a7 commit e3a4a03

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

src/config/config_type.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ macro_rules! create_config {
236236
use std::cmp;
237237
let max = 0;
238238
$( let max = cmp::max(max, stringify!($i).len()+1); )+
239-
let mut space_str = String::with_capacity(max);
240-
for _ in 0..max {
241-
space_str.push(' ');
242-
}
239+
let space_str = " ".repeat(max);
243240
writeln!(out, "Configuration Options:").unwrap();
244241
$(
245242
if $stb || include_unstable {

src/macros.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,12 @@ fn register_metavariable(
540540
name: &str,
541541
dollar_count: usize,
542542
) {
543-
let mut new_name = String::new();
544-
let mut old_name = String::new();
543+
let mut new_name = "$".repeat(dollar_count - 1);
544+
let mut old_name = "$".repeat(dollar_count);
545545

546-
old_name.push('$');
547-
for _ in 0..(dollar_count - 1) {
548-
new_name.push('$');
549-
old_name.push('$');
550-
}
551546
new_name.push('z');
552-
new_name.push_str(&name);
553-
old_name.push_str(&name);
547+
new_name.push_str(name);
548+
old_name.push_str(name);
554549

555550
result.push_str(&new_name);
556551
map.insert(old_name, new_name);

0 commit comments

Comments
 (0)