summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-15 05:42:36 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-15 05:42:36 +0000
commit18f7059688854cc10f7212563d37bac828a1cbef (patch)
treeda16301cf8cfb0808028258a868c975f29db80df /array.c
parentb750e49434834b04735987a48d2f3b68d9e55ef5 (diff)
* array.c (rb_ary_fill): should adjust array length correctly when
an array is expanded in the fill process. [ruby-core:06625] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/array.c b/array.c
index d14a49a716..e47ecf3fd8 100644
--- a/array.c
+++ b/array.c
@@ -1088,6 +1088,7 @@ rb_ary_insert(argc, argv, ary)
{
long pos;
+ if (argc == 1) return ary;
if (argc < 1) {
rb_raise(rb_eArgError, "wrong number of arguments (at least 1)");
}
@@ -1095,11 +1096,9 @@ rb_ary_insert(argc, argv, ary)
if (pos == -1) {
pos = RARRAY(ary)->len;
}
- else if (pos < 0) {
+ if (pos < 0) {
pos++;
}
-
- if (argc == 1) return ary;
rb_ary_splice(ary, pos, 0, rb_ary_new4(argc - 1, argv + 1));
return ary;
}
@@ -2265,7 +2264,6 @@ rb_ary_fill(argc, argv, ary)
if (beg > RARRAY(ary)->len) {
rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, end - RARRAY(ary)->len);
}
- RARRAY(ary)->len = end;
}
if (block_p) {
@@ -2276,9 +2274,11 @@ rb_ary_fill(argc, argv, ary)
v = rb_yield(LONG2NUM(i));
if (i>=RARRAY(ary)->len) break;
RARRAY(ary)->ptr[i] = v;
+ RARRAY(ary)->len = i+1;
}
}
else {
+ RARRAY(ary)->len = end;
p = RARRAY(ary)->ptr + beg;
pend = p + len;
while (p < pend) {