diff options
author | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-22 09:42:15 +0000 |
---|---|---|
committer | glass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-07-22 09:42:15 +0000 |
commit | 0780974482103f4b681f699b54068b9fe9eb5043 (patch) | |
tree | be79b9e0cf5a7b5cd79338489770f6894f4b6a95 | |
parent | fa20fb3728c622ff2e5fed3f843c5906d81b43c9 (diff) | |
download | ruby-0780974482103f4b681f699b54068b9fe9eb5043.tar.gz |
* string.c (rb_str_enumerate_chars): specify array capa
with str_strlen().
* string.c (rb_str_enumerate_codepoints): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42113 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | string.c | 26 |
2 files changed, 21 insertions, 12 deletions
@@ -1,3 +1,10 @@ +Mon Jul 22 18:39:52 2013 Masaki Matsushita <glass.saga@gmail.com> + + * string.c (rb_str_enumerate_chars): specify array capa + with str_strlen(). + + * string.c (rb_str_enumerate_codepoints): ditto. + Mon Jul 22 18:01:33 2013 Masaki Matsushita <glass.saga@gmail.com> * string.c (rb_str_enumerate_chars): specify array capa. @@ -6514,11 +6514,16 @@ rb_str_enumerate_chars(VALUE str, int wantarray) rb_encoding *enc; VALUE UNINITIALIZED_VAR(ary); + str = rb_str_new4(str); + ptr = RSTRING_PTR(str); + len = RSTRING_LEN(str); + enc = rb_enc_get(str); + if (rb_block_given_p()) { if (wantarray) { #if STRING_ENUMERATORS_WANTARRAY rb_warn("given block not used"); - ary = rb_ary_new_capa(rb_str_strlen(str)); + ary = rb_ary_new_capa(str_strlen(str, enc)); #else rb_warning("passing a block to String#chars is deprecated"); wantarray = 0; @@ -6527,15 +6532,11 @@ rb_str_enumerate_chars(VALUE str, int wantarray) } else { if (wantarray) - ary = rb_ary_new_capa(rb_str_strlen(str)); + ary = rb_ary_new_capa(str_strlen(str, enc)); else RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size); } - str = rb_str_new4(str); - ptr = RSTRING_PTR(str); - len = RSTRING_LEN(str); - enc = rb_enc_get(str); switch (ENC_CODERANGE(str)) { case ENC_CODERANGE_VALID: case ENC_CODERANGE_7BIT: @@ -6617,11 +6618,16 @@ rb_str_enumerate_codepoints(VALUE str, int wantarray) if (single_byte_optimizable(str)) return rb_str_enumerate_bytes(str, wantarray); + str = rb_str_new4(str); + ptr = RSTRING_PTR(str); + end = RSTRING_END(str); + enc = STR_ENC_GET(str); + if (rb_block_given_p()) { if (wantarray) { #if STRING_ENUMERATORS_WANTARRAY rb_warn("given block not used"); - ary = rb_ary_new(); + ary = rb_ary_new_capa(str_strlen(str, enc)); #else rb_warning("passing a block to String#codepoints is deprecated"); wantarray = 0; @@ -6630,15 +6636,11 @@ rb_str_enumerate_codepoints(VALUE str, int wantarray) } else { if (wantarray) - ary = rb_ary_new(); + ary = rb_ary_new_capa(str_strlen(str, enc)); else RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size); } - str = rb_str_new4(str); - ptr = RSTRING_PTR(str); - end = RSTRING_END(str); - enc = STR_ENC_GET(str); while (ptr < end) { c = rb_enc_codepoint_len(ptr, end, &n, enc); if (wantarray) |