summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorwatson1978 <watson1978@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-26 17:10:01 (GMT)
committerwatson1978 <watson1978@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-26 17:10:01 (GMT)
commit6270d595082b7470851f9815fd279e1ce0c3e214 (patch)
treebb229d6315e403aa32f3b0f18ae7d683f7ecd89e /array.c
parent43572889b3ecd8442574da98988fa187eaa04169 (diff)
Improve Array#concat performance if only one argument is given
* array.c (rb_ary_concat_multi): concatenate the array without generating temporary Array object if only one argument is given. This is very similar with r58886. Array#concat will be faster around 19%. [Fix GH-1634] ### Before Array#concat 2.187M (± 3.5%) i/s - 10.926M in 5.002829s ### After Array#concat 2.598M (± 1.8%) i/s - 13.008M in 5.008201s ### Test code require 'benchmark/ips' Benchmark.ips do |x| x.report "Array#concat" do |i| other = [4] i.times { [1, 2, 3].concat(other) } end end git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/array.c b/array.c
index 7d8309b..9ea4c05 100644
--- a/array.c
+++ b/array.c
@@ -3679,7 +3679,10 @@ rb_ary_concat_multi(int argc, VALUE *argv, VALUE ary)
{
rb_ary_modify_check(ary);
- if (argc > 0) {
+ if (argc == 1) {
+ rb_ary_concat(ary, argv[0]);
+ }
+ else if (argc > 1) {
int i;
VALUE args = rb_ary_tmp_new(argc);
for (i = 0; i < argc; i++) {