Use str::repeat

This commit is contained in:
Shotaro Yamada 2019-03-29 16:52:29 +09:00
parent 09940a70d0
commit e3a4a03657
2 changed files with 5 additions and 13 deletions

View File

@ -236,10 +236,7 @@ macro_rules! create_config {
use std::cmp;
let max = 0;
$( let max = cmp::max(max, stringify!($i).len()+1); )+
let mut space_str = String::with_capacity(max);
for _ in 0..max {
space_str.push(' ');
}
let space_str = " ".repeat(max);
writeln!(out, "Configuration Options:").unwrap();
$(
if $stb || include_unstable {

View File

@ -540,17 +540,12 @@ fn register_metavariable(
name: &str,
dollar_count: usize,
) {
let mut new_name = String::new();
let mut old_name = String::new();
let mut new_name = "$".repeat(dollar_count - 1);
let mut old_name = "$".repeat(dollar_count);
old_name.push('$');
for _ in 0..(dollar_count - 1) {
new_name.push('$');
old_name.push('$');
}
new_name.push('z');
new_name.push_str(&name);
old_name.push_str(&name);
new_name.push_str(name);
old_name.push_str(name);
result.push_str(&new_name);
map.insert(old_name, new_name);