Skip to content

Commit bcad3a5

Browse files
committed
Improve memory usage of libsyntax
Replaces some usage of `.to_string()` with `.into_string()` Signed-off-by: Peter Atashian <[email protected]>
1 parent 8780d9c commit bcad3a5

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

src/libsyntax/parse/token.rs

+41-41
Original file line numberDiff line numberDiff line change
@@ -165,45 +165,45 @@ pub fn binop_to_string(o: BinOp) -> &'static str {
165165

166166
pub fn to_string(t: &Token) -> String {
167167
match *t {
168-
EQ => "=".to_string(),
169-
LT => "<".to_string(),
170-
LE => "<=".to_string(),
171-
EQEQ => "==".to_string(),
172-
NE => "!=".to_string(),
173-
GE => ">=".to_string(),
174-
GT => ">".to_string(),
175-
NOT => "!".to_string(),
176-
TILDE => "~".to_string(),
177-
OROR => "||".to_string(),
178-
ANDAND => "&&".to_string(),
179-
BINOP(op) => binop_to_string(op).to_string(),
168+
EQ => "=".into_string(),
169+
LT => "<".into_string(),
170+
LE => "<=".into_string(),
171+
EQEQ => "==".into_string(),
172+
NE => "!=".into_string(),
173+
GE => ">=".into_string(),
174+
GT => ">".into_string(),
175+
NOT => "!".into_string(),
176+
TILDE => "~".into_string(),
177+
OROR => "||".into_string(),
178+
ANDAND => "&&".into_string(),
179+
BINOP(op) => binop_to_string(op).into_string(),
180180
BINOPEQ(op) => {
181-
let mut s = binop_to_string(op).to_string();
181+
let mut s = binop_to_string(op).into_string();
182182
s.push_str("=");
183183
s
184184
}
185185

186186
/* Structural symbols */
187-
AT => "@".to_string(),
188-
DOT => ".".to_string(),
189-
DOTDOT => "..".to_string(),
190-
DOTDOTDOT => "...".to_string(),
191-
COMMA => ",".to_string(),
192-
SEMI => ";".to_string(),
193-
COLON => ":".to_string(),
194-
MOD_SEP => "::".to_string(),
195-
RARROW => "->".to_string(),
196-
LARROW => "<-".to_string(),
197-
FAT_ARROW => "=>".to_string(),
198-
LPAREN => "(".to_string(),
199-
RPAREN => ")".to_string(),
200-
LBRACKET => "[".to_string(),
201-
RBRACKET => "]".to_string(),
202-
LBRACE => "{".to_string(),
203-
RBRACE => "}".to_string(),
204-
POUND => "#".to_string(),
205-
DOLLAR => "$".to_string(),
206-
QUESTION => "?".to_string(),
187+
AT => "@".into_string(),
188+
DOT => ".".into_string(),
189+
DOTDOT => "..".into_string(),
190+
DOTDOTDOT => "...".into_string(),
191+
COMMA => ",".into_string(),
192+
SEMI => ";".into_string(),
193+
COLON => ":".into_string(),
194+
MOD_SEP => "::".into_string(),
195+
RARROW => "->".into_string(),
196+
LARROW => "<-".into_string(),
197+
FAT_ARROW => "=>".into_string(),
198+
LPAREN => "(".into_string(),
199+
RPAREN => ")".into_string(),
200+
LBRACKET => "[".into_string(),
201+
RBRACKET => "]".into_string(),
202+
LBRACE => "{".into_string(),
203+
RBRACE => "}".into_string(),
204+
POUND => "#".into_string(),
205+
DOLLAR => "$".into_string(),
206+
QUESTION => "?".into_string(),
207207

208208
/* Literals */
209209
LIT_BYTE(b) => {
@@ -213,7 +213,7 @@ pub fn to_string(t: &Token) -> String {
213213
format!("'{}'", c.as_str())
214214
}
215215
LIT_INTEGER(c) | LIT_FLOAT(c) => {
216-
c.as_str().to_string()
216+
c.as_str().into_string()
217217
}
218218

219219
LIT_STR(s) => {
@@ -232,17 +232,17 @@ pub fn to_string(t: &Token) -> String {
232232
}
233233

234234
/* Name components */
235-
IDENT(s, _) => get_ident(s).get().to_string(),
235+
IDENT(s, _) => get_ident(s).get().into_string(),
236236
LIFETIME(s) => {
237237
format!("{}", get_ident(s))
238238
}
239-
UNDERSCORE => "_".to_string(),
239+
UNDERSCORE => "_".into_string(),
240240

241241
/* Other */
242-
DOC_COMMENT(s) => s.as_str().to_string(),
243-
EOF => "<eof>".to_string(),
244-
WS => " ".to_string(),
245-
COMMENT => "/* */".to_string(),
242+
DOC_COMMENT(s) => s.as_str().into_string(),
243+
EOF => "<eof>".into_string(),
244+
WS => " ".into_string(),
245+
COMMENT => "/* */".into_string(),
246246
SHEBANG(s) => format!("/* shebang: {}*/", s.as_str()),
247247

248248
INTERPOLATED(ref nt) => {
@@ -252,7 +252,7 @@ pub fn to_string(t: &Token) -> String {
252252
&NtTy(ref e) => ::print::pprust::ty_to_string(&**e),
253253
&NtPath(ref e) => ::print::pprust::path_to_string(&**e),
254254
_ => {
255-
let mut s = "an interpolated ".to_string();
255+
let mut s = "an interpolated ".into_string();
256256
match *nt {
257257
NtItem(..) => s.push_str("item"),
258258
NtBlock(..) => s.push_str("block"),

src/libsyntax/util/interner.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl fmt::Show for RcStr {
121121
impl RcStr {
122122
pub fn new(string: &str) -> RcStr {
123123
RcStr {
124-
string: Rc::new(string.to_string()),
124+
string: Rc::new(string.into_string()),
125125
}
126126
}
127127
}

0 commit comments

Comments
 (0)