Skip to content

Commit ff97ab4

Browse files
lucasmichotLucas Michot
andauthored
Change count array comparison to empty array comparison to improve performance (#59688)
Co-authored-by: Lucas Michot <lucas@zaiple.com>
1 parent ccdd692 commit ff97ab4

38 files changed

Lines changed: 58 additions & 60 deletions

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Rector\CodingStyle\Rector\Closure\ClosureDelegatingCallToFirstClassCallableRector;
88
use Rector\CodingStyle\Rector\FuncCall\ClosureFromCallableToFirstClassCallableRector;
99
use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector;
10+
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
1011
use Rector\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector;
1112
use Rector\Config\RectorConfig;
1213
use Rector\Php55\Rector\Class_\ClassConstantToSelfClassRector;
@@ -77,6 +78,7 @@
7778
'tests/Foundation/fixtures/bad-syntax-strategy.php',
7879
])
7980
->withRules([
81+
CountArrayToEmptyArrayComparisonRector::class,
8082
StrlenZeroToIdenticalEmptyStringRector::class,
8183
])
8284
->withPreparedSets(

src/Illuminate/Cache/DatabaseStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function get($key)
126126
*/
127127
public function many(array $keys)
128128
{
129-
if (count($keys) === 0) {
129+
if ($keys === []) {
130130
return [];
131131
}
132132

src/Illuminate/Cache/DynamoDbStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function get($key)
100100
*/
101101
public function many(array $keys)
102102
{
103-
if (count($keys) === 0) {
103+
if ($keys === []) {
104104
return [];
105105
}
106106

@@ -192,7 +192,7 @@ public function put($key, $value, $seconds)
192192
*/
193193
public function putMany(array $values, $seconds)
194194
{
195-
if (count($values) === 0) {
195+
if ($values === []) {
196196
return true;
197197
}
198198

src/Illuminate/Cache/MemcachedConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function getMemcached($connectionId, array $credentials, array $option
5151
$this->setCredentials($memcached, $credentials);
5252
}
5353

54-
if (count($options)) {
54+
if ($options !== []) {
5555
$memcached->setOptions($options);
5656
}
5757

src/Illuminate/Cache/MemoizedStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function many(array $keys)
6666
}
6767
}
6868

69-
if (count($missing) > 0) {
69+
if ($missing !== []) {
7070
$retrieved = tap($this->repository->many($missing), function ($values) {
7171
foreach ($values as $key => $value) {
7272
$this->cache[$this->prefix($key)] = $value;

src/Illuminate/Cache/RedisStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function get($key)
9696
*/
9797
public function many(array $keys)
9898
{
99-
if (count($keys) === 0) {
99+
if ($keys === []) {
100100
return [];
101101
}
102102

src/Illuminate/Cache/RedisTagSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function entries()
6666

6767
$entries = array_unique(array_keys($entries));
6868

69-
if (count($entries) === 0) {
69+
if ($entries === []) {
7070
continue;
7171
}
7272

src/Illuminate/Collections/Arr.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public static function forget(&$array, $keys)
412412

413413
$keys = (array) $keys;
414414

415-
if (count($keys) === 0) {
415+
if ($keys === []) {
416416
return;
417417
}
418418

src/Illuminate/Console/Command.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ protected function configureFromAttributes()
146146

147147
$signature = $reflection->getAttributes(Signature::class);
148148

149-
if (count($signature) > 0) {
149+
if ($signature !== []) {
150150
$signatureInstance = $signature[0]->newInstance();
151151

152152
$this->signature = $signatureInstance->signature;
@@ -158,23 +158,23 @@ protected function configureFromAttributes()
158158

159159
$description = $reflection->getAttributes(Description::class);
160160

161-
if (count($description) > 0) {
161+
if ($description !== []) {
162162
$this->description = $description[0]->newInstance()->description;
163163
}
164164

165165
$help = $reflection->getAttributes(Help::class);
166166

167-
if (count($help) > 0) {
167+
if ($help !== []) {
168168
$this->help = $help[0]->newInstance()->help;
169169
}
170170

171-
if (count($reflection->getAttributes(Hidden::class)) > 0) {
171+
if ($reflection->getAttributes(Hidden::class) !== []) {
172172
$this->hidden = true;
173173
}
174174

175175
$aliases = $reflection->getAttributes(Aliases::class);
176176

177-
if (count($aliases) > 0) {
177+
if ($aliases !== []) {
178178
$this->aliases = $aliases[0]->newInstance()->aliases;
179179
}
180180
}

src/Illuminate/Console/Scheduling/Schedule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ protected function dispatchNow($job)
295295
*/
296296
public function exec($command, array $parameters = [])
297297
{
298-
if (count($parameters)) {
298+
if ($parameters !== []) {
299299
$command .= ' '.$this->compileParameters($parameters);
300300
}
301301

0 commit comments

Comments
 (0)