diff options
author | ocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-15 07:06:00 +0000 |
---|---|---|
committer | ocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-15 07:06:00 +0000 |
commit | 518851f88d2bf0a66b829f8f05373f8ac8d1fdc4 (patch) | |
tree | 4a83f24ae6fc06a55c04332ccf7163ebea1aa5a6 /array.c | |
parent | 8950f856030ff9ed33ad7126d190a3f115c9eba8 (diff) |
* array.c (rb_ary_fill): tail elements were vanished when the middle
part of array was filled. (ie: [0,1,2,3,4].fill(-1,2,1) => [0,1,-1])
* test/ruby/test_array.rb (test_fill): added.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -2261,9 +2261,13 @@ rb_ary_fill(argc, argv, ary) REALLOC_N(RARRAY(ary)->ptr, VALUE, end); RARRAY(ary)->aux.capa = end; } - if (beg > RARRAY(ary)->len) { - rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, end - RARRAY(ary)->len); - } + RARRAY(ary)->len = end; + } + if (beg > RARRAY(ary)->len) { + rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, end - RARRAY(ary)->len); + } + else { + rb_mem_clear(RARRAY(ary)->ptr + beg, end - beg); } if (block_p) { @@ -2274,11 +2278,9 @@ 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) { |