Reduce allocations

This commit is contained in:
Shotaro Yamada 2018-10-15 21:20:03 +09:00
parent 6fb188bd43
commit 6c964fd030
3 changed files with 6 additions and 6 deletions

View File

@ -764,12 +764,12 @@ fn trim_custom_comment_prefix(s: &str) -> String {
// due to comment wrapping, a line that was originaly behind `#` is split over
// multiple lines, which needs then to be prefixed with a `#`
if !orig.trim_left().starts_with("# ") {
format!("# {}", orig)
Cow::from(format!("# {}", orig))
} else {
orig.to_string()
Cow::from(orig)
}
} else {
line.to_string()
Cow::from(line)
}
})
.collect::<Vec<_>>()

View File

@ -112,7 +112,7 @@ macro_rules! create_config {
cloned.width_heuristics = None;
::toml::to_string(&cloned)
.map_err(|e| format!("Could not output config: {}", e.to_string()))
.map_err(|e| format!("Could not output config: {}", e))
}
}

View File

@ -779,7 +779,7 @@ pub fn format_impl(
let outer_indent_str = offset.block_only().to_string_with_newline(context.config);
result.push_str(&inner_indent_str);
result.push_str(visitor.buffer.to_string().trim());
result.push_str(visitor.buffer.trim());
result.push_str(&outer_indent_str);
} else if need_newline || !context.config.empty_item_single_line() {
result.push_str(&sep);
@ -1137,7 +1137,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
let inner_indent_str = visitor.block_indent.to_string_with_newline(context.config);
result.push_str(&inner_indent_str);
result.push_str(visitor.buffer.to_string().trim());
result.push_str(visitor.buffer.trim());
result.push_str(&outer_indent_str);
} else if result.contains('\n') {
result.push_str(&outer_indent_str);