Skip to content

Commit

Permalink
Have #fmt use str::concat to build up the string instead of using bin…
Browse files Browse the repository at this point in the history
…ary +. Closes #2746.
  • Loading branch information
msullivan committed Jun 28, 2012
1 parent b2b4981 commit e9382ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ fn mk_uniq_vec_e(cx: ext_ctxt, sp: span, exprs: [@ast::expr]/~) ->
@ast::expr {
mk_vstore_e(cx, sp, mk_vec_e(cx, sp, exprs), ast::vstore_uniq)
}
fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: [@ast::expr]/~) ->
@ast::expr {
mk_vstore_e(cx, sp, mk_vec_e(cx, sp, exprs), ast::vstore_fixed(none))
}

fn mk_rec_e(cx: ext_ctxt, sp: span,
fields: [{ident: ast::ident, ex: @ast::expr}]/~) ->
Expand Down
14 changes: 8 additions & 6 deletions src/libsyntax/ext/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
let args = [cnv_expr, arg]/~;
ret mk_call(cx, arg.span, path, args);
}

fn make_new_conv(cx: ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) ->
@ast::expr {
// FIXME: Move validation code into core::extfmt (Issue #2249)
Expand Down Expand Up @@ -243,13 +244,12 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
}
let fmt_sp = args[0].span;
let mut n = 0u;
let mut tmp_expr = mk_str(cx, sp, "");
let nargs = vec::len::<@ast::expr>(args);
let mut piece_exprs = []/~;
let nargs = args.len();
for pieces.each {|pc|
alt pc {
piece_string(s) {
let s_expr = mk_str(cx, fmt_sp, s);
tmp_expr = mk_binary(cx, fmt_sp, ast::add, tmp_expr, s_expr);
vec::push(piece_exprs, mk_str(cx, fmt_sp, s));
}
piece_conv(conv) {
n += 1u;
Expand All @@ -262,7 +262,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
log_conv(conv);
let arg_expr = args[n];
let c_expr = make_new_conv(cx, fmt_sp, conv, arg_expr);
tmp_expr = mk_binary(cx, fmt_sp, ast::add, tmp_expr, c_expr);
vec::push(piece_exprs, c_expr);
}
}
}
Expand All @@ -273,7 +273,9 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
(sp, #fmt["too many arguments to #fmt. found %u, expected %u",
nargs, expected_nargs]);
}
ret tmp_expr;

let arg_vec = mk_fixed_vec_e(cx, fmt_sp, piece_exprs);
ret mk_call(cx, fmt_sp, [@"str", @"concat"]/~, [arg_vec]/~);
}
//
// Local Variables:
Expand Down

0 comments on commit e9382ef

Please sign in to comment.