mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_str_each_char): performance improvement, and stop if
shortened in the block. [ruby-dev:33189] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15140 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3106b96ac8
commit
00190701e0
2 changed files with 19 additions and 3 deletions
|
@ -1,3 +1,8 @@
|
|||
Sun Jan 20 13:06:01 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_each_char): performance improvement, and stop if
|
||||
shortened in the block. [ruby-dev:33189]
|
||||
|
||||
Sun Jan 20 09:12:26 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||
|
||||
* common.mk: use -Ks when read insns.def. [ruby-dev#33185]
|
||||
|
|
17
string.c
17
string.c
|
@ -4590,11 +4590,22 @@ rb_str_each_byte(VALUE str)
|
|||
static VALUE
|
||||
rb_str_each_char(VALUE str)
|
||||
{
|
||||
int i, len = str_strlen(str, 0);
|
||||
int i, len, n;
|
||||
const char *ptr, *s;
|
||||
rb_encoding *enc;
|
||||
|
||||
RETURN_ENUMERATOR(str, 0, 0);
|
||||
for (i=0; i<len; i++) {
|
||||
rb_yield(rb_str_substr(str, i, 1));
|
||||
ptr = RSTRING_PTR(str);
|
||||
len = RSTRING_LEN(str);
|
||||
enc = rb_enc_get(str);
|
||||
n = rb_enc_mbclen(ptr, ptr + len, enc);
|
||||
for (i = 0; i < len; i += n) {
|
||||
rb_yield(rb_str_subseq(str, i, n));
|
||||
ptr = RSTRING_PTR(str);
|
||||
len = RSTRING_LEN(str);
|
||||
enc = rb_enc_get(str);
|
||||
s = rb_enc_left_char_head(ptr, ptr + i, enc);
|
||||
n = rb_enc_mbclen(s, ptr + len, enc);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue