Skip to content

Commit

Permalink
[Performance] Avoid unnecessary IO dumpFile() called when file has no…
Browse files Browse the repository at this point in the history
… change on FileProcessor (#5079)

* [Performance] Remove unnecessary IO dumpFile() when file has no change on FileProcessor

* update comment

* [ci-review] Rector Rectify

* cs fix

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Sep 24, 2023
1 parent 2e86f76 commit bd4c8dd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,17 @@ private function printFile(File $file, Configuration $configuration): void
}
}

if (! $configuration->isDryRun()) {
$this->formatPerservingPrinter->dumpFile($file->getFilePath(), $newContent);
// change file content early to make $file->hasChanged() based on new content
$file->changeFileContent($newContent);
if ($configuration->isDryRun()) {
return;
}

$file->changeFileContent($newContent);
if (! $file->hasChanged()) {
return;
}

$this->formatPerservingPrinter->dumpFile($file->getFilePath(), $newContent);
}

private function parseFileNodes(File $file): void
Expand Down

0 comments on commit bd4c8dd

Please sign in to comment.