Skip to content

Commit 2e3e0c0

Browse files
committed
Avoid needless creation of unique strings in fmt!()
Only the first portion has to be owned, as it acts as the buffer for the constructed string. The remaining strings can be static.
1 parent 2ae44a0 commit 2e3e0c0

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/libsyntax/ext/fmt.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,13 @@ fn pieces_to_expr(cx: @ext_ctxt, sp: span,
273273
match pc {
274274
/* Raw strings get appended via str::push_str */
275275
PieceString(s) => {
276-
let portion = mk_uniq_str(cx, fmt_sp, s);
277-
278276
/* If this is the first portion, then initialize the local
279277
buffer with it directly. If it's actually the only piece,
280278
then there's no need for it to be mutable */
281279
if i == 0 {
282-
stms.push(mk_local(cx, fmt_sp, npieces > 1, ident, portion));
280+
stms.push(mk_local(cx, fmt_sp, npieces > 1, ident, mk_uniq_str(cx, fmt_sp, s)));
283281
} else {
284-
let args = ~[mk_mut_addr_of(cx, fmt_sp, buf()), portion];
282+
let args = ~[mk_mut_addr_of(cx, fmt_sp, buf()), mk_base_str(cx, fmt_sp, s)];
285283
let call = mk_call_global(cx,
286284
fmt_sp,
287285
~[str_ident, push_ident],

0 commit comments

Comments
 (0)