Reduce some String clones

This commit is contained in:
greg 2018-10-01 20:46:58 -07:00
parent 76046b134a
commit a5c3c383dc

View File

@ -315,7 +315,7 @@ impl<T: Terminal> Completer<T> for TabCompleteHandler {
if cmd.starts_with(word) {
completions.push(Completion {
completion: format!("{}{}", if top { ":" } else { "" }, cmd),
display: Some(cmd.clone()),
display: Some(cmd.to_string()),
suffix: ::linefeed::complete::Suffix::Some(' ')
})
}
@ -350,21 +350,21 @@ impl CommandTree {
fn term(s: &str, help: Option<&str>) -> CommandTree {
CommandTree::Terminal(s.to_string(), help.map(|x| x.to_string()))
}
fn get_cmd(&self) -> String {
fn get_cmd(&self) -> &str {
match self {
CommandTree::Terminal(s, _) => s.to_string(),
CommandTree::NonTerminal(s, _, _) => s.to_string(),
CommandTree::Top(_) => "".to_string(),
CommandTree::Terminal(s, _) => s.as_str(),
CommandTree::NonTerminal(s, _, _) => s.as_str(),
CommandTree::Top(_) => "",
}
}
fn get_help(&self) -> String {
fn get_help(&self) -> &str {
match self {
CommandTree::Terminal(_, h) => h.as_ref().map(|h| h.clone()).unwrap_or(format!("")),
CommandTree::NonTerminal(_, _, h) => h.as_ref().map(|h| h.clone()).unwrap_or(format!("")),
CommandTree::Top(_) => "".to_string(),
CommandTree::Terminal(_, h) => h.as_ref().map(|s| s.as_str()).unwrap_or(""),
CommandTree::NonTerminal(_, _, h) => h.as_ref().map(|s| s.as_str()).unwrap_or(""),
CommandTree::Top(_) => ""
}
}
fn get_children(&self) -> Vec<String> {
fn get_children(&self) -> Vec<&str> {
match self {
CommandTree::Terminal(_, _) => vec![],
CommandTree::NonTerminal(_, children, _) => children.iter().map(|x| x.get_cmd()).collect(),