syntax: shuffle some allocation out of binop_to_str

This commit is contained in:
Corey Richardson 2014-05-20 10:37:08 -07:00
parent 507c1a0fc9
commit 024df5c8a6
1 changed files with 13 additions and 13 deletions

View File

@ -136,18 +136,18 @@ impl fmt::Show for Nonterminal {
}
}
pub fn binop_to_str(o: BinOp) -> String {
pub fn binop_to_str(o: BinOp) -> &'static str {
match o {
PLUS => "+".to_string(),
MINUS => "-".to_string(),
STAR => "*".to_string(),
SLASH => "/".to_string(),
PERCENT => "%".to_string(),
CARET => "^".to_string(),
AND => "&".to_string(),
OR => "|".to_string(),
SHL => "<<".to_string(),
SHR => ">>".to_string()
PLUS => "+",
MINUS => "-",
STAR => "*",
SLASH => "/",
PERCENT => "%",
CARET => "^",
AND => "&",
OR => "|",
SHL => "<<",
SHR => ">>"
}
}
@ -164,9 +164,9 @@ pub fn to_str(t: &Token) -> String {
TILDE => "~".to_string(),
OROR => "||".to_string(),
ANDAND => "&&".to_string(),
BINOP(op) => binop_to_str(op),
BINOP(op) => binop_to_str(op).to_string(),
BINOPEQ(op) => {
let mut s = binop_to_str(op);
let mut s = binop_to_str(op).to_strbuf();
s.push_str("=");
s
}