string.c: use rb_check_funcall
* string.c (rb_str_cmp_m): use rb_check_funcall instead of respond_to and call. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38043 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1dbc720c0d
commit
c08785a362
@ -1,4 +1,7 @@
|
|||||||
Fri Nov 30 17:43:39 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Nov 30 17:43:45 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_cmp_m): use rb_check_funcall instead of respond_to
|
||||||
|
and call.
|
||||||
|
|
||||||
* string.c (rb_str_cmp_m): return fixed value, one of -1,0,+1 always.
|
* string.c (rb_str_cmp_m): return fixed value, one of -1,0,+1 always.
|
||||||
|
|
||||||
|
6
string.c
6
string.c
@ -2385,15 +2385,15 @@ rb_str_cmp_m(VALUE str1, VALUE str2)
|
|||||||
int result;
|
int result;
|
||||||
|
|
||||||
if (!RB_TYPE_P(str2, T_STRING)) {
|
if (!RB_TYPE_P(str2, T_STRING)) {
|
||||||
|
VALUE tmp;
|
||||||
if (!rb_respond_to(str2, rb_intern("to_str"))) {
|
if (!rb_respond_to(str2, rb_intern("to_str"))) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
else if (!rb_respond_to(str2, rb_intern("<=>"))) {
|
else if ((tmp = rb_check_funcall(str2, rb_intern("<=>"), 1, &str1)) ==
|
||||||
|
Qundef) {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VALUE tmp = rb_funcall(str2, rb_intern("<=>"), 1, str1);
|
|
||||||
|
|
||||||
if (NIL_P(tmp)) return Qnil;
|
if (NIL_P(tmp)) return Qnil;
|
||||||
result = -rb_cmpint(tmp, str1, str2);
|
result = -rb_cmpint(tmp, str1, str2);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user