Skip to content

Commit

Permalink
Avoid needless creation of unique strings in fmt!()
Browse files Browse the repository at this point in the history
Only the first portion has to be owned, as it acts as the buffer for the
constructed string. The remaining strings can be static.
  • Loading branch information
dotdash committed May 3, 2013
1 parent 2ae44a0 commit 2e3e0c0
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/libsyntax/ext/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,13 @@ fn pieces_to_expr(cx: @ext_ctxt, sp: span,
match pc {
/* Raw strings get appended via str::push_str */
PieceString(s) => {
let portion = mk_uniq_str(cx, fmt_sp, s);

/* If this is the first portion, then initialize the local
buffer with it directly. If it's actually the only piece,
then there's no need for it to be mutable */
if i == 0 {
stms.push(mk_local(cx, fmt_sp, npieces > 1, ident, portion));
stms.push(mk_local(cx, fmt_sp, npieces > 1, ident, mk_uniq_str(cx, fmt_sp, s)));
} else {
let args = ~[mk_mut_addr_of(cx, fmt_sp, buf()), portion];
let args = ~[mk_mut_addr_of(cx, fmt_sp, buf()), mk_base_str(cx, fmt_sp, s)];
let call = mk_call_global(cx,
fmt_sp,
~[str_ident, push_ident],
Expand Down

0 comments on commit 2e3e0c0

Please sign in to comment.