Skip to content

Commit a9a676f

Browse files
staabmsebastianbergmann
authored andcommitted
Improve performance by skipping empty lines after filter has been applied
1 parent 74e0adf commit a9a676f

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/CodeCoverage.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ private function applyCoversAndUsesFilter(RawCodeCoverageData $rawData, array|fa
403403
foreach (array_keys($filesWithNoCoverage) as $fileWithNoCoverage) {
404404
$rawData->removeCoverageDataForFile($fileWithNoCoverage);
405405
}
406+
$rawData->skipEmptyLines();
406407

407408
if (is_array($linesToBeCovered)) {
408409
foreach ($linesToBeCovered as $fileToBeCovered => $includedLines) {

src/Data/RawCodeCoverageData.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ private function __construct(array $lineCoverage, array $functionCoverage)
103103
{
104104
$this->lineCoverage = $lineCoverage;
105105
$this->functionCoverage = $functionCoverage;
106-
107-
$this->skipEmptyLines();
108106
}
109107

110108
public function clear(): void
@@ -251,7 +249,7 @@ public function removeCoverageDataForLines(string $filename, array $lines): void
251249
*
252250
* @see https://github.com/sebastianbergmann/php-code-coverage/issues/799
253251
*/
254-
private function skipEmptyLines(): void
252+
public function skipEmptyLines(): void
255253
{
256254
foreach ($this->lineCoverage as $filename => $coverage) {
257255
foreach ($this->getEmptyLinesForFile($filename) as $emptyLine) {

tests/tests/Data/RawCodeCoverageDataTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ public function testCoverageForFileWithInlineAnnotations(): void
326326
33,
327327
],
328328
);
329+
$coverage->skipEmptyLines();
329330

330331
$this->assertEquals(
331332
[

0 commit comments

Comments
 (0)