Skip to content

Commit

Permalink
* array.c (rb_ary_cat): new function to concat objects into array.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Mar 8, 2012
1 parent 729e66b commit e78ff08
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Fri Mar 9 00:25:02 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>

* array.c (rb_ary_cat): new function to concat objects into array.

Thu Mar 8 16:44:02 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>

* .gdbinit (rb_numtable_entry): update for recent refactoring of
Expand Down
3 changes: 3 additions & 0 deletions README.EXT
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ listed below:
rb_ary_shift(VALUE ary)
rb_ary_unshift(VALUE ary, VALUE val)

rb_ary_cat(VALUE ary, const VALUE *ptr, long len)

Appends len elements of objects from ptr to the array.

2. Extending Ruby with C

Expand Down
4 changes: 4 additions & 0 deletions README.EXT.ja
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ Rubyが用意している関数を用いてください.
rb_ary_shift(VALUE ary)
rb_ary_unshift(VALUE ary, VALUE val)

rb_ary_cat(VALUE ary, const VALUE *ptr, long len)

配列aryにptrからlen個のオブジェクトを追加する.

2.Rubyの機能を使う

原理的にRubyで書けることはCでも書けます.RubyそのものがCで記
Expand Down
19 changes: 14 additions & 5 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,19 @@ rb_ary_push_1(VALUE ary, VALUE item)
return ary;
}

VALUE
rb_ary_cat(VALUE ary, const VALUE *ptr, long len)
{
long oldlen;

rb_ary_modify(ary);
oldlen = RARRAY_LEN(ary);
ary_resize_capa(ary, oldlen + len);
MEMCPY(RARRAY_PTR(ary) + oldlen, ptr, VALUE, len);
ARY_SET_LEN(ary, oldlen + len);
return ary;
}

/*
* call-seq:
* ary.push(obj, ... ) -> ary
Expand All @@ -771,11 +784,7 @@ rb_ary_push_1(VALUE ary, VALUE item)
static VALUE
rb_ary_push_m(int argc, VALUE *argv, VALUE ary)
{
rb_ary_modify(ary);
while (argc--) {
rb_ary_push_1(ary, *argv++);
}
return ary;
return rb_ary_cat(ary, argv, argc);
}

VALUE
Expand Down
1 change: 1 addition & 0 deletions internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct vtm; /* defined by timev.h */
/* array.c */
VALUE rb_ary_last(int, VALUE *, VALUE);
void rb_ary_set_len(VALUE, long);
VALUE rb_ary_cat(VALUE, const VALUE *, long);

/* bignum.c */
VALUE rb_big_fdiv(VALUE x, VALUE y);
Expand Down

0 comments on commit e78ff08

Please sign in to comment.