-
Notifications
You must be signed in to change notification settings - Fork 440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small performance optimization #555
Small performance optimization #555
Conversation
src/Task/Git/CommitMessage.php
Outdated
@@ -156,7 +156,7 @@ private function enforceTextWidth(ContextInterface $context): TaskResult | |||
} | |||
} | |||
|
|||
if (count($errors) > 0) { | |||
if (\count($errors) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to if (\count($errors) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/Task/PhpMd.php
Outdated
@@ -58,12 +58,12 @@ public function run(ContextInterface $context): TaskResultInterface | |||
$extensions = $config['triggered_by']; | |||
|
|||
$files = $context->getFiles(); | |||
if (0 !== count($whitelistPatterns)) { | |||
if (0 !== \count($whitelistPatterns)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to if (\count($whitelistPatterns)) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/Task/YamlLint.php
Outdated
@@ -54,10 +54,10 @@ public function run(ContextInterface $context): TaskResultInterface | |||
|
|||
/** @var FilesCollection $files */ | |||
$files = $context->getFiles()->name($extensions); | |||
if (count($whitelistPatterns) >= 1) { | |||
if (\count($whitelistPatterns) >= 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to if (\count($whitelistPatterns)) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/Task/Phpcs.php
Outdated
@@ -70,12 +70,12 @@ public function run(ContextInterface $context): TaskResultInterface | |||
|
|||
/** @var \GrumPHP\Collection\FilesCollection $files */ | |||
$files = $context->getFiles(); | |||
if (0 !== count($whitelistPatterns)) { | |||
if (0 !== \count($whitelistPatterns)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to if (\count($whitelistPatterns)) {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fc9bf08
to
359738a
Compare
src/Util/Regex.php
Outdated
@@ -33,7 +33,7 @@ public function __construct(string $string) | |||
private function isRegex(string $string): bool | |||
{ | |||
if (preg_match('/^(.{3,}?)['.self::ALLOWED_MODIFIERS.']*$/', $string, $m)) { | |||
$start = substr($m[1], 0, 1); | |||
$start = $m[1][0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to use a string function here to avoid confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -45,7 +45,7 @@ private function formatOutput(string $output): string | |||
{ | |||
$result = static::RESET_COLOR; | |||
foreach (array_filter(explode("\n", $output)) as $lineNumber => $line) { | |||
$result .= preg_match('/^[0-9]+/', $line) ? $this->trimOutputLine($line, (int) $lineNumber) : $line; | |||
$result .= preg_match('/^\d+/', $line) ? $this->trimOutputLine($line, (int) $lineNumber) : $line; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer [0-9] here since it is easier to folow then the \d alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
1952e7e
to
76c5b93
Compare
Hi @laurieplo, Thanks for your effort. Can you fix the failing tests/build? |
76c5b93
to
170fb07
Compare
Yes, sorry @Landerstraeten ! It is fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @laurieplo
170fb07
to
f43f215
Compare
A lot of very small changes that will affect performance and maintanability (fully-qualified function calls, ===/!==, return optimization, ...)