]> git.lizzy.rs Git - rust.git/commitdiff
syntax: shuffle some allocation out of binop_to_str
authorCorey Richardson <corey@octayn.net>
Tue, 20 May 2014 17:37:08 +0000 (10:37 -0700)
committerCorey Richardson <corey@octayn.net>
Wed, 4 Jun 2014 04:00:55 +0000 (21:00 -0700)
src/libsyntax/parse/token.rs

index 34f508e42a1eb970385115463a025190d939dc55..8263c7c6852f5ec2b65c31bb46bbed9cb459c0af 100644 (file)
@@ -136,18 +136,18 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-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
       }