Skip to content

Commit 0bba915

Browse files
committed
Refactor method addAll
1 parent 221d91c commit 0bba915

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

spec/ArrayListSpec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ function () {
203203
$tmp_array_list->add('string2');
204204
$this->arrayList->addAll($tmp_array_list);
205205
expect($this->arrayList->isEmpty())->toEqual(false);
206+
expect($this->arrayList->size())->toEqual(2);
206207
expect($this->arrayList->get(0))->toEqual('string1');
207208
expect($this->arrayList->get(1))->toEqual('string2');
208209
});

src/ArrayList.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,8 @@ public function addAll(...$args): bool
151151
return true;
152152
}
153153
$this->guardCollectionType($collection);
154-
foreach ($collection as $value) {
155-
$this->values[] = $value;
156-
$this->size++;
157-
158-
}
154+
$this->values = \array_merge($this->values, $collection->toArray());
155+
$this->size += $collection->size();
159156
return true;
160157
},
161158
"integer, {$typeCollection}" => function ($index, Collection $collection) {

0 commit comments

Comments
 (0)