mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
19991018
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_4@547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a438c908aa
commit
fd1fe9cf1d
1 changed files with 6 additions and 13 deletions
19
array.c
19
array.c
|
|
@ -943,26 +943,19 @@ rb_ary_delete_at(ary, at)
|
|||
VALUE ary;
|
||||
VALUE at;
|
||||
{
|
||||
long i1, i2, pos;
|
||||
long i, pos = NUM2LONG(at), len = RARRAY(ary)->len;
|
||||
VALUE del = Qnil;
|
||||
|
||||
rb_ary_modify(ary);
|
||||
if (pos >= len) return Qnil;
|
||||
if (pos < 0) pos += len;
|
||||
if (pos < 0) return Qnil;
|
||||
|
||||
rb_ary_modify(ary);
|
||||
pos = NUM2LONG(at);
|
||||
for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
|
||||
if (i1 == pos) {
|
||||
del = RARRAY(ary)->ptr[i1];
|
||||
continue;
|
||||
}
|
||||
if (i1 != i2) {
|
||||
RARRAY(ary)->ptr[i2] = RARRAY(ary)->ptr[i1];
|
||||
}
|
||||
i2++;
|
||||
del = RARRAY(ary)->ptr[pos];
|
||||
for (i = pos + 1; i < len; i++, pos++) {
|
||||
RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i];
|
||||
}
|
||||
RARRAY(ary)->len = i2;
|
||||
RARRAY(ary)->len = pos;
|
||||
|
||||
return del;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue