Skip to content

Commit bea0bb7

Browse files
committed
[perf][expr] drop do while from FileProcessor
1 parent 27281c6 commit bea0bb7

2 files changed

Lines changed: 56 additions & 48 deletions

File tree

‎src/Application/FileProcessor.php‎

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -56,65 +56,73 @@ public function processFile(File $file, Configuration $configuration): FileProce
5656
return new FileProcessResult([$parsingSystemError], null, false);
5757
}
5858

59-
$fileHasChanged = false;
59+
// $fileHasChanged = false;
6060
$filePath = $file->getFilePath();
6161

62-
do {
63-
$file->changeHasChanged(false);
62+
// do {
63+
// $file->changeHasChanged(false);
6464

65-
// every rule and post rector records a line change when it mutates the AST
66-
$changeCountBeforePass = count($file->getRectorWithLineChanges());
65+
// every rule and post rector records a line change when it mutates the AST
66+
// $changeCountBeforePass = count($file->getRectorWithLineChanges());
6767

68-
// 1. change nodes with Rector Rules
69-
$newStmts = $this->rectorNodeTraverser->traverse($file->getNewStmts(), $file);
68+
// 1. change nodes with Rector Rules
69+
$newStmts = $this->rectorNodeTraverser->traverse($file->getNewStmts(), $file);
7070

71-
// 2. apply post rectors
72-
$postNewStmts = $this->postFileProcessor->traverse($newStmts, $file);
71+
// 2. apply post rectors
72+
$postNewStmts = $this->postFileProcessor->traverse($newStmts, $file);
7373

74-
// 3. this is needed for new tokens added in "afterTraverse()"
75-
$file->changeNewStmts($postNewStmts);
74+
// 3. this is needed for new tokens added in "afterTraverse()"
75+
$file->changeNewStmts($postNewStmts);
7676

77-
// file never changed and this pass changed nothing: the print would just reproduce the
78-
// original content, so skip the expensive format-preserving print entirely.
79-
// once the file has changed we keep printing every pass, as a reprint can still
80-
// stabilize the output (e.g. drop a leftover trailing comma)
81-
if (! $fileHasChanged && count($file->getRectorWithLineChanges()) === $changeCountBeforePass) {
82-
break;
83-
}
84-
85-
// 4. print to file or string
86-
// important to detect if file has changed
87-
$this->printFile($file, $configuration, $filePath);
77+
// file never changed and this pass changed nothing: the print would just reproduce the
78+
// original content, so skip the expensive format-preserving print entirely.
79+
// once the file has changed we keep printing every pass, as a reprint can still
80+
// stabilize the output (e.g. drop a leftover trailing comma)
81+
// if (! $fileHasChanged && count($file->getRectorWithLineChanges()) === $changeCountBeforePass) {
82+
// break;
83+
// }
8884

89-
// no change in current iteration, stop
90-
if (! $file->hasChanged()) {
91-
break;
92-
}
85+
// if (! $file->hasChanged()) {
86+
// continue;
9387

94-
$fileHasChanged = true;
95-
} while (true);
88+
// 4. print to file or string
89+
// important to detect if file has changed
90+
// $this->printFile($file, $configuration, $filePath);
9691

97-
// 5. add as cacheable if not changed at all
98-
if (! $fileHasChanged) {
92+
// no change in current iteration, stop
93+
if (! $file->hasChanged()) {
9994
$this->changedFilesDetector->addCacheableFile($filePath);
95+
return new FileProcessResult([], $file->getFileDiff(), $file->hasChanged());
96+
97+
// break;
10098
} else {
101-
// when changed, set final status changed to true
102-
// to ensure it make sense to verify in next process when needed
103-
$file->changeHasChanged(true);
99+
$this->printFile($file, $configuration, $filePath);
104100
}
105101

102+
// $fileHasChanged = true;
103+
// } while (true);
104+
105+
// 5. add as cacheable if not changed at all
106+
// if (! $fileHasChanged) {
107+
// $this->changedFilesDetector->addCacheableFile($filePath);
108+
// } else {
109+
// // when changed, set final status changed to true
110+
// // to ensure it make sense to verify in next process when needed
111+
// $file->changeHasChanged(true);
112+
// }
113+
106114
$rectorWithLineChanges = $file->getRectorWithLineChanges();
107-
if ($file->hasChanged() || $rectorWithLineChanges !== []) {
108-
$currentFileDiff = $this->fileDiffFactory->createFileDiffWithLineChanges(
109-
$configuration->shouldShowDiffs(),
110-
$file,
111-
$file->getOriginalFileContent(),
112-
$file->getFileContent(),
113-
$file->getRectorWithLineChanges()
114-
);
115-
116-
$file->setFileDiff($currentFileDiff);
117-
}
115+
// if ($file->hasChanged() || $rectorWithLineChanges !== []) {
116+
$currentFileDiff = $this->fileDiffFactory->createFileDiffWithLineChanges(
117+
$configuration->shouldShowDiffs(),
118+
$file,
119+
$file->getOriginalFileContent(),
120+
$file->getFileContent(),
121+
$file->getRectorWithLineChanges()
122+
);
123+
124+
$file->setFileDiff($currentFileDiff);
125+
// }
118126

119127
return new FileProcessResult([], $file->getFileDiff(), $file->hasChanged());
120128
}

‎src/ValueObject/Application/File.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public function hasChanged(): bool
8787
return $this->hasChanged;
8888
}
8989

90-
public function changeHasChanged(bool $status): void
91-
{
92-
$this->hasChanged = $status;
93-
}
90+
// public function changeHasChanged(bool $status): void
91+
// {
92+
// $this->hasChanged = $status;
93+
// }
9494

9595
public function setFileDiff(FileDiff $fileDiff): void
9696
{

0 commit comments

Comments
 (0)