@@ -49,26 +49,34 @@ public function __construct(
4949
5050 public function merge (self $ data ): self
5151 {
52- $ branches = $ this ->branches ;
53-
54- foreach ($ data ->branches as $ branchId => $ branch ) {
55- if (!isset ($ branches [$ branchId ])) {
56- $ branches [$ branchId ] = $ branch ;
57- } else {
58- $ branches [$ branchId ] = $ branches [$ branchId ]->merge ($ branch );
52+ $ branches = null ;
53+ if ($ data ->branches !== $ this ->branches ) {
54+ $ branches = $ this ->branches ;
55+ foreach ($ data ->branches as $ branchId => $ branch ) {
56+ if (!isset ($ branches [$ branchId ])) {
57+ $ branches [$ branchId ] = $ branch ;
58+ } else {
59+ $ branches [$ branchId ] = $ branches [$ branchId ]->merge ($ branch );
60+ }
5961 }
6062 }
6163
62- $ paths = $ this ->paths ;
63-
64- foreach ($ data ->paths as $ pathId => $ path ) {
65- if (!isset ($ paths [$ pathId ])) {
66- $ paths [$ pathId ] = $ path ;
67- } else {
68- $ paths [$ pathId ] = $ paths [$ pathId ]->merge ($ path );
64+ $ paths = null ;
65+ if ($ data ->paths !== $ this ->paths ) {
66+ $ paths = $ this ->paths ;
67+ foreach ($ data ->paths as $ pathId => $ path ) {
68+ if (!isset ($ paths [$ pathId ])) {
69+ $ paths [$ pathId ] = $ path ;
70+ } else {
71+ $ paths [$ pathId ] = $ paths [$ pathId ]->merge ($ path );
72+ }
6973 }
7074 }
7175
76+ if ($ branches === null && $ paths === null ) {
77+ return $ this ;
78+ }
79+
7280 return new self (
7381 $ branches ,
7482 $ paths ,
@@ -83,6 +91,9 @@ public function recordBranchHit(int $branchId, string $testCaseId): void
8391 $ this ->branches [$ branchId ]->recordHit ($ testCaseId );
8492 }
8593
94+ /**
95+ * @param TestIdType $testCaseId
96+ */
8697 public function recordPathHit (int $ pathId , string $ testCaseId ): void
8798 {
8899 $ this ->paths [$ pathId ]->recordHit ($ testCaseId );
0 commit comments