summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-08 15:25:04 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-08 15:25:04 (GMT)
commite78ff08968357431c87914641f294185cfda3218 (patch)
tree280555e2d3940352028047d2493430a34be73f5b
parent729e66b3c1d90547c9b4eb2a045d9095075f71b8 (diff)
* array.c (rb_ary_cat): new function to concat objects into array.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34948 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--README.EXT3
-rw-r--r--README.EXT.ja4
-rw-r--r--array.c19
-rw-r--r--internal.h1
5 files changed, 26 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 05d4d50..ec1f6c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/README.EXT b/README.EXT
index c57dba0..ad45255 100644
--- a/README.EXT
+++ b/README.EXT
@@ -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
diff --git a/README.EXT.ja b/README.EXT.ja
index d1ec3d8..6b0cb11 100644
--- a/README.EXT.ja
+++ b/README.EXT.ja
@@ -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で記
diff --git a/array.c b/array.c
index 397e3f5..64b97f4 100644
--- a/array.c
+++ b/array.c
@@ -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
@@ -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
diff --git a/internal.h b/internal.h
index f5a463e..64a67e1 100644
--- a/internal.h
+++ b/internal.h
@@ -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);