Skip to content

Commit 4096d89

Browse files
committed
Improve performance of CostAnnotatedStateSet::mergeWith()
1 parent 76c160a commit 4096d89

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/StateSet/CostAnnotatedStateSet.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@ public function add(int $state, int $cost): void
4545

4646
public function mergeWith(CostAnnotatedStateSet $stateSet): self
4747
{
48-
$newSet = new CostAnnotatedStateSet();
49-
foreach ($this->set as $state => $cost) {
50-
$newSet->add($state, $cost);
51-
}
48+
$clone = clone $this;
5249

5350
foreach ($stateSet->all() as $state => $cost) {
54-
$newSet->add($state, $cost);
51+
$clone->add($state, $cost);
5552
}
5653

57-
return $newSet;
54+
return $clone;
5855
}
5956
}

0 commit comments

Comments
 (0)