Skip to content

Commit 024df5c

Browse files
committed
syntax: shuffle some allocation out of binop_to_str
1 parent 507c1a0 commit 024df5c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/libsyntax/parse/token.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,18 @@ impl fmt::Show for Nonterminal {
136136
}
137137
}
138138

139-
pub fn binop_to_str(o: BinOp) -> String {
139+
pub fn binop_to_str(o: BinOp) -> &'static str {
140140
match o {
141-
PLUS => "+".to_string(),
142-
MINUS => "-".to_string(),
143-
STAR => "*".to_string(),
144-
SLASH => "/".to_string(),
145-
PERCENT => "%".to_string(),
146-
CARET => "^".to_string(),
147-
AND => "&".to_string(),
148-
OR => "|".to_string(),
149-
SHL => "<<".to_string(),
150-
SHR => ">>".to_string()
141+
PLUS => "+",
142+
MINUS => "-",
143+
STAR => "*",
144+
SLASH => "/",
145+
PERCENT => "%",
146+
CARET => "^",
147+
AND => "&",
148+
OR => "|",
149+
SHL => "<<",
150+
SHR => ">>"
151151
}
152152
}
153153

@@ -164,9 +164,9 @@ pub fn to_str(t: &Token) -> String {
164164
TILDE => "~".to_string(),
165165
OROR => "||".to_string(),
166166
ANDAND => "&&".to_string(),
167-
BINOP(op) => binop_to_str(op),
167+
BINOP(op) => binop_to_str(op).to_string(),
168168
BINOPEQ(op) => {
169-
let mut s = binop_to_str(op);
169+
let mut s = binop_to_str(op).to_strbuf();
170170
s.push_str("=");
171171
s
172172
}

0 commit comments

Comments
 (0)