ruby-changes:45040
From: nobu <ko1@a...>
Date: Mon, 19 Dec 2016 12:12:17 +0900 (JST)
Subject: [ruby-changes:45040] nobu:r57112 (trunk): re.c: NAME_TO_NUMBER
nobu 2016-12-19 12:11:57 +0900 (Mon, 19 Dec 2016) New Revision: 57112 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57112 Log: re.c: NAME_TO_NUMBER * re.c (namev_to_backref_number, rb_reg_regsub): extract name to backref number check as NAME_TO_NUMBER. Modified files: trunk/re.c Index: re.c =================================================================== --- re.c (revision 57111) +++ re.c (revision 57112) @@ -1829,6 +1829,11 @@ name_to_backref_error(VALUE name) https://github.com/ruby/ruby/blob/trunk/re.c#L1829 name); } +#define NAME_TO_NUMBER(regs, re, name, name_ptr, name_end) \ + (NIL_P(re) ? 0 : \ + !rb_enc_compatible(RREGEXP_SRC(re), (name)) ? 0 : \ + name_to_backref_number((regs), (re), (name_ptr), (name_end))) + static int namev_to_backref_number(struct re_registers *regs, VALUE re, VALUE name) { @@ -1839,9 +1844,9 @@ namev_to_backref_number(struct re_regist https://github.com/ruby/ruby/blob/trunk/re.c#L1844 name = rb_sym2str(name); /* fall through */ case T_STRING: - if (NIL_P(re) || !rb_enc_compatible(RREGEXP_SRC(re), name) || - (num = name_to_backref_number(regs, re, - RSTRING_PTR(name), RSTRING_END(name))) < 1) { + num = NAME_TO_NUMBER(regs, re, name, + RSTRING_PTR(name), RSTRING_END(name)); + if (num < 1) { name_to_backref_error(name); } return num; @@ -3730,9 +3735,7 @@ rb_reg_regsub(VALUE str, VALUE src, stru https://github.com/ruby/ruby/blob/trunk/re.c#L3735 if (name_end < e) { VALUE n = rb_str_subseq(str, (long)(name - RSTRING_PTR(str)), (long)(name_end - name)); - if (NIL_P(regexp) || - !rb_enc_compatible(RREGEXP_SRC(regexp), n) || - (no = name_to_backref_number(regs, regexp, name, name_end)) < 1) { + if ((no = NAME_TO_NUMBER(regs, regexp, n, name, name_end)) < 1) { name_to_backref_error(n); } p = s = name_end + clen; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/