From 73d3336830f1f1f866df05e0b1ab2ba6c1fd4edf Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 14 Mar 2016 07:53:39 +0000 Subject: optimize named capture assignment * compile.c (compile_named_capture_assign): optimize named capture assignments, by replacing repeating global variable accesses with `dup`, and by returning the matched result instead of re-getting it from the MatchData. * parse.y (reg_named_capture_assign_gen): build just assignment nodes for the optimization. ex. `/(?.)/ =~ "bar"` - old ``` 0000 putstring "bar" 0002 opt_regexpmatch1 /(?.)/ 0004 pop 0005 getglobal $~ 0007 branchunless 25 0009 getglobal $~ 0011 putobject :x 0013 opt_aref 0016 setlocal_OP__WC__0 2 0018 getglobal $~ 0020 putobject_OP_INT2FIX_O_0_C_ 0021 opt_send_without_block 0024 leave 0025 putobject nil 0027 setlocal_OP__WC__0 2 0029 putobject nil 0031 leave ``` - new ``` 0000 putstring "bar" 0002 opt_regexpmatch1 /(?.)/ 0004 getglobal $~ 0006 dup 0007 branchunless 14 0009 putobject :x 0011 opt_aref 0014 setlocal_OP__WC__0 2 0016 leave ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54100 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- node.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'node.c') diff --git a/node.c b/node.c index fa3189d128..01a496977b 100644 --- a/node.c +++ b/node.c @@ -583,8 +583,12 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node) ANN("format: [nd_recv] =~ [nd_value]"); ANN("example: /foo/ =~ 'foo'"); F_NODE(nd_recv, "regexp (receiver)"); - LAST_NODE; + if (!node->nd_args) LAST_NODE; F_NODE(nd_value, "string (argument)"); + if (node->nd_args) { + LAST_NODE; + F_NODE(nd_args, "named captures"); + } break; case NODE_MATCH3: -- cgit v1.2.3