From e3a4a036574da637367a7f99e6de0edc1b93c764 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Fri, 29 Mar 2019 16:52:29 +0900 Subject: [PATCH] Use str::repeat --- src/config/config_type.rs | 5 +---- src/macros.rs | 13 ++++--------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/config/config_type.rs b/src/config/config_type.rs index 14c2dcbb8db..7c4298dcf1c 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -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 { diff --git a/src/macros.rs b/src/macros.rs index 18df24b45c8..088b3e4490f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -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);