зеркало из https://github.com/github/ruby.git
* string.c (rb_str_rindex): refactoring and avoid to call str_nth() if
pos == 0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
fc3b9361d4
Коммит
8b126d59b3
|
@ -1,3 +1,8 @@
|
|||
Wed Jul 31 16:43:30 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||
|
||||
* string.c (rb_str_rindex): refactoring and avoid to call str_nth() if
|
||||
pos == 0.
|
||||
|
||||
Wed Jul 31 14:41:36 2013 Akinori MUSHA <knu@iDaemons.org>
|
||||
|
||||
* lib/set.rb: [DOC] Add a couple of notes on Hash as storage.
|
||||
|
|
28
string.c
28
string.c
|
@ -2673,27 +2673,33 @@ rb_str_rindex(VALUE str, VALUE sub, long pos)
|
|||
long len, slen;
|
||||
char *s, *sbeg, *e, *t;
|
||||
rb_encoding *enc;
|
||||
int singlebyte = single_byte_optimizable(str);
|
||||
int singlebyte;
|
||||
|
||||
enc = rb_enc_check(str, sub);
|
||||
if (is_broken_string(sub)) {
|
||||
return -1;
|
||||
}
|
||||
len = str_strlen(str, enc);
|
||||
if (is_broken_string(sub)) return -1;
|
||||
singlebyte = single_byte_optimizable(str);
|
||||
len = singlebyte ? RSTRING_LEN(str) : str_strlen(str, enc);
|
||||
slen = str_strlen(sub, enc);
|
||||
|
||||
/* substring longer than string */
|
||||
if (len < slen) return -1;
|
||||
if (len - pos < slen) {
|
||||
pos = len - slen;
|
||||
}
|
||||
if (len == 0) {
|
||||
return pos;
|
||||
}
|
||||
if (len - pos < slen) pos = len - slen;
|
||||
if (len == 0) return pos;
|
||||
|
||||
sbeg = RSTRING_PTR(str);
|
||||
e = RSTRING_END(str);
|
||||
t = RSTRING_PTR(sub);
|
||||
slen = RSTRING_LEN(sub);
|
||||
|
||||
if (pos == 0) {
|
||||
if (memcmp(sbeg, t, slen) == 0)
|
||||
return 0;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
s = str_nth(sbeg, e, pos, enc, singlebyte);
|
||||
|
||||
while (s) {
|
||||
if (memcmp(s, t, slen) == 0) {
|
||||
return pos;
|
||||
|
|
Загрузка…
Ссылка в новой задаче