ruby-changes:45041
From: nobu <ko1@a...>
Date: Mon, 19 Dec 2016 13:07:45 +0900 (JST)
Subject: [ruby-changes:45041] nobu:r57114 (trunk): re.c: RB_TYPE_P
nobu 2016-12-19 13:07:40 +0900 (Mon, 19 Dec 2016) New Revision: 57114 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57114 Log: re.c: RB_TYPE_P * re.c (match_backref_number, namev_to_backref_number): use RB_TYPE_P instead of switching by TYPE. Modified files: trunk/re.c Index: re.c =================================================================== --- re.c (revision 57113) +++ re.c (revision 57114) @@ -1123,18 +1123,13 @@ match_backref_number(VALUE match, VALUE https://github.com/ruby/ruby/blob/trunk/re.c#L1123 VALUE regexp = RMATCH(match)->regexp; match_check(match); - switch (TYPE(backref)) { - default: - return NUM2INT(backref); - - case T_SYMBOL: + if (SYMBOL_P(backref)) { backref = rb_sym2str(backref); - /* fall through */ - - case T_STRING: - name = StringValueCStr(backref); - break; } + else if (!RB_TYPE_P(backref, T_STRING)) { + return NUM2INT(backref); + } + name = StringValueCStr(backref); num = name_to_backref_number(regs, regexp, name, name + strlen(name)); @@ -1839,21 +1834,18 @@ namev_to_backref_number(struct re_regist https://github.com/ruby/ruby/blob/trunk/re.c#L1834 { int num; - switch (TYPE(name)) { - case T_SYMBOL: + if (SYMBOL_P(name)) { name = rb_sym2str(name); - /* fall through */ - case T_STRING: - num = NAME_TO_NUMBER(regs, re, name, - RSTRING_PTR(name), RSTRING_END(name)); - if (num < 1) { - name_to_backref_error(name); - } - return num; - - default: + } + else if (!RB_TYPE_P(name, T_STRING)) { return -1; } + num = NAME_TO_NUMBER(regs, re, name, + RSTRING_PTR(name), RSTRING_END(name)); + if (num < 1) { + name_to_backref_error(name); + } + return num; } static VALUE -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/