diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-16 09:30:03 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-02-16 09:30:03 +0000 |
commit | 0ad3d7ce2d679a92d2904430919c835639993a32 (patch) | |
tree | 37a9440b3252ba633f9bd8582bc0c40cf48a3b4d | |
parent | 7eeba5f440975912a63ee6e9da014c4a727cb565 (diff) | |
download | ruby-0ad3d7ce2d679a92d2904430919c835639993a32.tar.gz |
* string.c (str_strlen): little more optimize.
(rb_enc_nth): remove needless variable 'c'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15507 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | string.c | 20 |
2 files changed, 16 insertions, 9 deletions
@@ -1,3 +1,8 @@ +Sat Feb 16 18:25:14 2008 NARUSE, Yui <naruse@ruby-lang.org> + + * string.c (str_strlen): little more optimize. + (rb_enc_nth): remove needless variable 'c'. + Sat Feb 16 18:00:13 2008 Tanaka Akira <akr@fsij.org> * encoding.c (rb_enc_compatible): empty strings are always compatible. @@ -643,9 +643,11 @@ str_strlen(VALUE str, rb_encoding *enc) } while (s < t) { unsigned long d = *s; - d = (~d ^ (d&(d<<1)))&NONASCII_MASK; - d = (d>>7) + (d>>15); - d = d + (d>>16); + d = ~d | (d<<1); + d &= NONASCII_MASK; + d >>= 7; + d += (d>>8); + d += (d>>16); #if NONASCII_MASK == 0x8080808080808080UL d = d + (d>>32); #endif @@ -657,6 +659,7 @@ str_strlen(VALUE str, rb_encoding *enc) for (; p<e; p++) { if (((*p)&0xC0) != 0x80) len++; } + return len; } else #endif @@ -664,6 +667,9 @@ str_strlen(VALUE str, rb_encoding *enc) if (len < 0) { rb_raise(rb_eArgError, "invalid mbstring sequence"); } + if (ENC_CODERANGE(str) != ENC_CODERANGE_VALID && enc == STR_ENC_GET(str)) { + ENC_CODERANGE_SET(str, ENC_CODERANGE_VALID); + } return len; } @@ -949,8 +955,6 @@ rb_str_s_try_convert(VALUE dummy, VALUE str) char* rb_enc_nth(const char *p, const char *e, int nth, rb_encoding *enc) { - int c; - if (rb_enc_mbmaxlen(enc) == 1) { p += nth; } @@ -981,10 +985,8 @@ rb_enc_nth(const char *p, const char *e, int nth, rb_encoding *enc) return (char *)p; } else { - for (c=0; p<e && nth--; c++) { - int n = rb_enc_mbclen(p, e, enc); - - p += n; + while (p<e && nth--) { + p += rb_enc_mbclen(p, e, enc); } } if (p > e) p = e; |