mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: shortcut argument check
* string.c (str_casecmp, str_casecmp_p): split to skip argument check when it is a String certainly. * string.c (sym_casecmp, sym_casecmp_p): shortcut argument checks. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8bc0729857
commit
8c661ba264
1 changed files with 19 additions and 4 deletions
23
string.c
23
string.c
|
@ -3189,6 +3189,9 @@ rb_str_cmp_m(VALUE str1, VALUE str2)
|
|||
return INT2FIX(result);
|
||||
}
|
||||
|
||||
static VALUE str_casecmp(VALUE str1, VALUE str2);
|
||||
static VALUE str_casecmp_p(VALUE str1, VALUE str2);
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* str.casecmp(other_str) -> -1, 0, +1, or nil
|
||||
|
@ -3209,12 +3212,18 @@ rb_str_cmp_m(VALUE str1, VALUE str2)
|
|||
|
||||
static VALUE
|
||||
rb_str_casecmp(VALUE str1, VALUE str2)
|
||||
{
|
||||
StringValue(str2);
|
||||
return str_casecmp(str1, str2);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
str_casecmp(VALUE str1, VALUE str2)
|
||||
{
|
||||
long len;
|
||||
rb_encoding *enc;
|
||||
char *p1, *p1end, *p2, *p2end;
|
||||
|
||||
StringValue(str2);
|
||||
enc = rb_enc_compatible(str1, str2);
|
||||
if (!enc) {
|
||||
return Qnil;
|
||||
|
@ -3285,12 +3294,18 @@ rb_str_casecmp(VALUE str1, VALUE str2)
|
|||
|
||||
static VALUE
|
||||
rb_str_casecmp_p(VALUE str1, VALUE str2)
|
||||
{
|
||||
StringValue(str2);
|
||||
return str_casecmp_p(str1, str2);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
str_casecmp_p(VALUE str1, VALUE str2)
|
||||
{
|
||||
rb_encoding *enc;
|
||||
VALUE folded_str1, folded_str2;
|
||||
VALUE fold_opt = sym_fold;
|
||||
|
||||
StringValue(str2);
|
||||
enc = rb_enc_compatible(str1, str2);
|
||||
if (!enc) {
|
||||
return Qnil;
|
||||
|
@ -9827,7 +9842,7 @@ sym_casecmp(VALUE sym, VALUE other)
|
|||
if (!SYMBOL_P(other)) {
|
||||
return Qnil;
|
||||
}
|
||||
return rb_str_casecmp(rb_sym2str(sym), rb_sym2str(other));
|
||||
return str_casecmp(rb_sym2str(sym), rb_sym2str(other));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -9857,7 +9872,7 @@ sym_casecmp_p(VALUE sym, VALUE other)
|
|||
if (!SYMBOL_P(other)) {
|
||||
return Qnil;
|
||||
}
|
||||
return rb_str_casecmp_p(rb_sym2str(sym), rb_sym2str(other));
|
||||
return str_casecmp_p(rb_sym2str(sym), rb_sym2str(other));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue