diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-18 06:43:08 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-04-18 06:43:08 +0000 |
commit | c37ac7ba91f5944adef234683617aa5681b8f97b (patch) | |
tree | 4b5aad0acbc60a1835d740e08c6cd1b54680571b | |
parent | 0ab9abe06939b41b151c95b287f6d283d5e5e9ea (diff) | |
download | ruby-c37ac7ba91f5944adef234683617aa5681b8f97b.tar.gz |
* 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
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | string.c | 17 |
2 files changed, 15 insertions, 6 deletions
@@ -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 @@ -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 |