From a5c3c383dcc4ed9dd22e1265cfbd8ea331f00af6 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 1 Oct 2018 20:46:58 -0700 Subject: [PATCH] Reduce some String clones --- schala-repl/src/repl.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/schala-repl/src/repl.rs b/schala-repl/src/repl.rs index a66ea79..7a8ae36 100644 --- a/schala-repl/src/repl.rs +++ b/schala-repl/src/repl.rs @@ -315,7 +315,7 @@ impl Completer 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 { + fn get_children(&self) -> Vec<&str> { match self { CommandTree::Terminal(_, _) => vec![], CommandTree::NonTerminal(_, children, _) => children.iter().map(|x| x.get_cmd()).collect(),