Skip to content

Commit c74e830

Browse files
perf: dedupe render keys via hash set instead of in_array (#155)
1 parent 7b6db77 commit c74e830

3 files changed

Lines changed: 6 additions & 13 deletions

File tree

src/Validator/HtmlTagValidator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ public function renderDetailedOutput(OutputInterface $output, array $issues): vo
129129
$key = $details['key'] ?? 'unknown';
130130
$files = $details['files'] ?? [];
131131

132-
if (!in_array($key, $allKeys)) {
133-
$allKeys[] = $key;
134-
}
132+
$allKeys[$key] = true;
135133

136134
foreach ($files as $filePath => $fileInfo) {
137135
$fileName = basename((string) $filePath);
@@ -154,7 +152,7 @@ public function renderDetailedOutput(OutputInterface $output, array $issues): vo
154152
$header[] = $fileName;
155153
}
156154

157-
foreach ($allKeys as $key) {
155+
foreach (array_keys($allKeys) as $key) {
158156
$row = [$key];
159157
foreach ($fileOrder as $fileName) {
160158
$value = $allFilesData[$key][$fileName] ?? '';

src/Validator/MismatchValidator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,7 @@ public function renderDetailedOutput(OutputInterface $output, array $issues): vo
144144
$files = $details['files'] ?? [];
145145
$currentFile = basename($issue->getFile());
146146

147-
if (!in_array($key, $allKeys, true)) {
148-
$allKeys[] = $key;
149-
}
147+
$allKeys[$key] = true;
150148

151149
foreach ($files as $fileInfo) {
152150
$fileName = basename($fileInfo['file'] ?? '');
@@ -179,7 +177,7 @@ public function renderDetailedOutput(OutputInterface $output, array $issues): vo
179177
}
180178
}
181179

182-
foreach ($allKeys as $key) {
180+
foreach (array_keys($allKeys) as $key) {
183181
$row = [$key];
184182
foreach ($fileOrder as $fileName) {
185183
$value = $allFilesData[$key][$fileName] ?? null;

src/Validator/PlaceholderConsistencyValidator.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Symfony\Component\Console\Output\OutputInterface;
2323

2424
use function count;
25-
use function in_array;
2625

2726
/**
2827
* PlaceholderConsistencyValidator.
@@ -128,9 +127,7 @@ public function renderDetailedOutput(OutputInterface $output, array $issues): vo
128127
$key = $details['key'] ?? 'unknown';
129128
$files = $details['files'] ?? [];
130129

131-
if (!in_array($key, $allKeys)) {
132-
$allKeys[] = $key;
133-
}
130+
$allKeys[$key] = true;
134131

135132
foreach ($files as $filePath => $fileInfo) {
136133
$fileName = basename((string) $filePath);
@@ -153,7 +150,7 @@ public function renderDetailedOutput(OutputInterface $output, array $issues): vo
153150
$header[] = $fileName;
154151
}
155152

156-
foreach ($allKeys as $key) {
153+
foreach (array_keys($allKeys) as $key) {
157154
$row = [$key];
158155
foreach ($fileOrder as $fileName) {
159156
$value = $allFilesData[$key][$fileName] ?? '';

0 commit comments

Comments
 (0)