From d5c8ad535961968b40823512ccdb12e38f1ed529 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 29 Jan 2008 08:03:51 +0000 Subject: * insns.def (toregexp): generate a regexp from strings instead of one string. * re.c (rb_reg_new_ary): defined for toregexp. it concatenates strings after each string is preprocessed. * compile.c (compile_dstr_fragments): split from compile_dstr. (compile_dstr): call compile_dstr_fragments. (compile_dregx): defined for dynamic regexp. (iseq_compile_each): use compile_dregx for dynamic regexp. [ruby-dev:33400] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15311 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- compile.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index f6545d56d8..ca4b28b66c 100644 --- a/compile.c +++ b/compile.c @@ -1853,7 +1853,7 @@ iseq_set_sequence_stackcaching(rb_iseq_t *iseq, LINK_ANCHOR *anchor) static int -compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) +compile_dstr_fragments(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int *cntp) { NODE *list = node->nd_next; VALUE lit = node->nd_lit; @@ -1867,11 +1867,29 @@ compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) cnt++; list = list->nd_next; } + *cntp = cnt; + + return COMPILE_OK; +} +static int +compile_dstr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) +{ + int cnt; + compile_dstr_fragments(iseq, ret, node, &cnt); ADD_INSN1(ret, nd_line(node), concatstrings, INT2FIX(cnt)); return COMPILE_OK; } +static int +compile_dregx(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node) +{ + int cnt; + compile_dstr_fragments(iseq, ret, node, &cnt); + ADD_INSN2(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag), INT2FIX(cnt)); + return COMPILE_OK; +} + static int compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * cond, LABEL *then_label, LABEL *else_label) @@ -4111,8 +4129,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) break; } case NODE_DREGX:{ - compile_dstr(iseq, ret, node); - ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag)); + compile_dregx(iseq, ret, node); if (poped) { ADD_INSN(ret, nd_line(node), pop); @@ -4128,8 +4145,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_INSN2(ret, nd_line(node), onceinlinecache, 0, lend); ADD_INSN(ret, nd_line(node), pop); - compile_dstr(iseq, ret, node); - ADD_INSN1(ret, nd_line(node), toregexp, INT2FIX(node->nd_cflag)); + compile_dregx(iseq, ret, node); ADD_INSN1(ret, nd_line(node), setinlinecache, lstart); ADD_LABEL(ret, lend); -- cgit v1.2.3