diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-01-15 14:12:07 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-15 14:12:07 -0800 |
| commit | 002d840d170e2b87c0d34dc2bf8a7bc15a014791 (patch) | |
| tree | 2027a3f496b5d5e29418c71e84b52e65d02afe1a /src/libsyntax | |
| parent | 6dc94f744ef1513991939488594e2c1f0ebb110a (diff) | |
| parent | b75cee84254744990cdc158ae2304a5378e88448 (diff) | |
| download | rust-002d840d170e2b87c0d34dc2bf8a7bc15a014791.tar.gz rust-002d840d170e2b87c0d34dc2bf8a7bc15a014791.zip | |
rollup merge of #21199: dotdash/decode_lamba
Currently, we build a closure that does nothing but pass its argument through to another function, this is rather wasteful and creates lots of unnecessary closures.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/deriving/decodable.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 7c65d2b4ff4..f73023ddd1e 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -92,11 +92,10 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span, let recurse = vec!(cx.ident_of(krate), cx.ident_of("Decodable"), cx.ident_of("decode")); + let exprdecode = cx.expr_path(cx.path_global(trait_span, recurse)); // throw an underscore in front to suppress unused variable warnings let blkarg = cx.ident_of("_d"); let blkdecoder = cx.expr_ident(trait_span, blkarg); - let calldecode = cx.expr_call_global(trait_span, recurse, vec!(blkdecoder.clone())); - let lambdadecode = cx.lambda_expr_1(trait_span, calldecode, blkarg); return match *substr.fields { StaticStruct(_, ref summary) => { @@ -116,7 +115,7 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span, cx.expr_method_call(span, blkdecoder.clone(), read_struct_field, vec!(cx.expr_str(span, name), cx.expr_uint(span, field), - lambdadecode.clone()))) + exprdecode.clone()))) }); let result = cx.expr_ok(trait_span, result); cx.expr_method_call(trait_span, @@ -147,7 +146,7 @@ fn decodable_substructure(cx: &mut ExtCtxt, trait_span: Span, let idx = cx.expr_uint(span, field); cx.expr_try(span, cx.expr_method_call(span, blkdecoder.clone(), rvariant_arg, - vec!(idx, lambdadecode.clone()))) + vec!(idx, exprdecode.clone()))) }); arms.push(cx.arm(v_span, |
