summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 09:42:15 +0000
committerglass <glass@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-22 09:42:15 +0000
commit0780974482103f4b681f699b54068b9fe9eb5043 (patch)
treebe79b9e0cf5a7b5cd79338489770f6894f4b6a95 /string.c
parentfa20fb3728c622ff2e5fed3f843c5906d81b43c9 (diff)
* 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
Diffstat (limited to 'string.c')
-rw-r--r--string.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/string.c b/string.c
index a4c76d4f7b..f101a94c32 100644
--- a/string.c
+++ b/string.c
@@ -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)