mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
fa20fb3728
commit
0780974482
2 changed files with 21 additions and 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>
|
Mon Jul 22 18:01:33 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||||
|
|
||||||
* string.c (rb_str_enumerate_chars): specify array capa.
|
* string.c (rb_str_enumerate_chars): specify array capa.
|
||||||
|
|
26
string.c
26
string.c
|
@ -6514,11 +6514,16 @@ rb_str_enumerate_chars(VALUE str, int wantarray)
|
||||||
rb_encoding *enc;
|
rb_encoding *enc;
|
||||||
VALUE UNINITIALIZED_VAR(ary);
|
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 (rb_block_given_p()) {
|
||||||
if (wantarray) {
|
if (wantarray) {
|
||||||
#if STRING_ENUMERATORS_WANTARRAY
|
#if STRING_ENUMERATORS_WANTARRAY
|
||||||
rb_warn("given block not used");
|
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
|
#else
|
||||||
rb_warning("passing a block to String#chars is deprecated");
|
rb_warning("passing a block to String#chars is deprecated");
|
||||||
wantarray = 0;
|
wantarray = 0;
|
||||||
|
@ -6527,15 +6532,11 @@ rb_str_enumerate_chars(VALUE str, int wantarray)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (wantarray)
|
if (wantarray)
|
||||||
ary = rb_ary_new_capa(rb_str_strlen(str));
|
ary = rb_ary_new_capa(str_strlen(str, enc));
|
||||||
else
|
else
|
||||||
RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size);
|
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)) {
|
switch (ENC_CODERANGE(str)) {
|
||||||
case ENC_CODERANGE_VALID:
|
case ENC_CODERANGE_VALID:
|
||||||
case ENC_CODERANGE_7BIT:
|
case ENC_CODERANGE_7BIT:
|
||||||
|
@ -6617,11 +6618,16 @@ rb_str_enumerate_codepoints(VALUE str, int wantarray)
|
||||||
if (single_byte_optimizable(str))
|
if (single_byte_optimizable(str))
|
||||||
return rb_str_enumerate_bytes(str, wantarray);
|
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 (rb_block_given_p()) {
|
||||||
if (wantarray) {
|
if (wantarray) {
|
||||||
#if STRING_ENUMERATORS_WANTARRAY
|
#if STRING_ENUMERATORS_WANTARRAY
|
||||||
rb_warn("given block not used");
|
rb_warn("given block not used");
|
||||||
ary = rb_ary_new();
|
ary = rb_ary_new_capa(str_strlen(str, enc));
|
||||||
#else
|
#else
|
||||||
rb_warning("passing a block to String#codepoints is deprecated");
|
rb_warning("passing a block to String#codepoints is deprecated");
|
||||||
wantarray = 0;
|
wantarray = 0;
|
||||||
|
@ -6630,15 +6636,11 @@ rb_str_enumerate_codepoints(VALUE str, int wantarray)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (wantarray)
|
if (wantarray)
|
||||||
ary = rb_ary_new();
|
ary = rb_ary_new_capa(str_strlen(str, enc));
|
||||||
else
|
else
|
||||||
RETURN_SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size);
|
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) {
|
while (ptr < end) {
|
||||||
c = rb_enc_codepoint_len(ptr, end, &n, enc);
|
c = rb_enc_codepoint_len(ptr, end, &n, enc);
|
||||||
if (wantarray)
|
if (wantarray)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue