* string.c (str_strlen): use enc_strlen if the coderange is known.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45618 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0ab9abe069
commit
c37ac7ba91
@ -1,3 +1,7 @@
|
||||
Fri Apr 18 14:32:40 2014 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* string.c (str_strlen): use enc_strlen if the coderange is known.
|
||||
|
||||
Fri Apr 18 14:21:21 2014 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* string.c (enc_strlen): move UTF-8 optimization from str_strlen to
|
||||
|
17
string.c
17
string.c
@ -1187,6 +1187,9 @@ rb_enc_strlen(const char *p, const char *e, rb_encoding *enc)
|
||||
return enc_strlen(p, e, enc, ENC_CODERANGE_UNKNOWN);
|
||||
}
|
||||
|
||||
/* To get strlen with cr
|
||||
* Note that given cr is not used.
|
||||
*/
|
||||
long
|
||||
rb_enc_strlen_cr(const char *p, const char *e, rb_encoding *enc, int *cr)
|
||||
{
|
||||
@ -1243,12 +1246,11 @@ rb_enc_strlen_cr(const char *p, const char *e, rb_encoding *enc, int *cr)
|
||||
return c;
|
||||
}
|
||||
|
||||
/* enc must be compatible with str's enc */
|
||||
/* enc must be str's enc or rb_enc_check(str, str2) */
|
||||
static long
|
||||
str_strlen(VALUE str, rb_encoding *enc)
|
||||
{
|
||||
const char *p, *e;
|
||||
long n;
|
||||
int cr;
|
||||
|
||||
if (single_byte_optimizable(str)) return RSTRING_LEN(str);
|
||||
@ -1257,11 +1259,14 @@ str_strlen(VALUE str, rb_encoding *enc)
|
||||
e = RSTRING_END(str);
|
||||
cr = ENC_CODERANGE(str);
|
||||
|
||||
n = rb_enc_strlen_cr(p, e, enc, &cr);
|
||||
if (cr) {
|
||||
ENC_CODERANGE_SET(str, cr);
|
||||
if (cr == ENC_CODERANGE_UNKNOWN) {
|
||||
long n = rb_enc_strlen_cr(p, e, enc, &cr);
|
||||
if (cr) ENC_CODERANGE_SET(str, cr);
|
||||
return n;
|
||||
}
|
||||
else {
|
||||
return enc_strlen(p, e, enc, cr);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
long
|
||||
|
Loading…
x
Reference in New Issue
Block a user