aboutsummaryrefslogtreecommitdiffstats
path: root/node.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-14 07:53:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-14 07:53:39 +0000
commitea5e885a958967c999e15512c6e72defab232de4 (patch)
tree35b1713bacf79e68f79ec0f5a361e8ac1acae2ba /node.c
parenta4e6f7d707293a71727ad18e75aae9639ba423f3 (diff)
downloadruby-ea5e885a958967c999e15512c6e72defab232de4.tar.gz
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. `/(?<x>.)/ =~ "bar"` - old ``` 0000 putstring "bar" 0002 opt_regexpmatch1 /(?<x>.)/ 0004 pop 0005 getglobal $~ 0007 branchunless 25 0009 getglobal $~ 0011 putobject :x 0013 opt_aref <callinfo!mid:[], argc:1, ARGS_SIMPLE> 0016 setlocal_OP__WC__0 2 0018 getglobal $~ 0020 putobject_OP_INT2FIX_O_0_C_ 0021 opt_send_without_block <callinfo!mid:begin, argc:1, ARGS_SIMPLE> 0024 leave 0025 putobject nil 0027 setlocal_OP__WC__0 2 0029 putobject nil 0031 leave ``` - new ``` 0000 putstring "bar" 0002 opt_regexpmatch1 /(?<x>.)/ 0004 getglobal $~ 0006 dup 0007 branchunless 14 0009 putobject :x 0011 opt_aref <callinfo!mid:[], argc:1, ARGS_SIMPLE> 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
Diffstat (limited to 'node.c')
-rw-r--r--node.c6
1 files changed, 5 insertions, 1 deletions
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: