summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-18 14:10:29 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-18 14:10:29 +0000
commit642273c070f6121c0ad3f24752b7b91fd63670c3 (patch)
treedd1354ce704bbab488291e3144d3097d1c5134df /array.c
parentff964e8aa2db3cfb7d33cfb344f92ed6d8355b40 (diff)
* array.c (rb_ary_first): call rb_ary_subseq() instead of pushing
values by itself. [ruby-talk:252062] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c13
1 files changed, 3 insertions, 10 deletions
diff --git a/array.c b/array.c
index acc59d2..e2bbf2b 100644
--- a/array.c
+++ b/array.c
@@ -748,17 +748,10 @@ rb_ary_first(argc, argv, ary)
return RARRAY(ary)->ptr[0];
}
else {
- VALUE nv, result;
- long n, i;
+ VALUE n;
- rb_scan_args(argc, argv, "01", &nv);
- n = NUM2LONG(nv);
- if (n > RARRAY(ary)->len) n = RARRAY(ary)->len;
- result = rb_ary_new2(n);
- for (i=0; i<n; i++) {
- rb_ary_push(result, RARRAY(ary)->ptr[i]);
- }
- return result;
+ rb_scan_args(argc, argv, "01", &n);
+ return rb_ary_subseq(ary, 0, NUM2LONG(n));
}
}