Skip to content

Commit da79b7f

Browse files
committed
Micro-optimizations for global functions https://github.com/Roave/FunctionFQNReplacer for more info.
1 parent 52695f8 commit da79b7f

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/CacheMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function clear()
6565
*/
6666
public function count()
6767
{
68-
return count($this->cache);
68+
return \count($this->cache);
6969
}
7070

7171
/**

src/DataLoader.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function (callable $resolve, callable $reject) use ($key) {
7676
'reject' => $reject,
7777
];
7878

79-
if (count($this->promiseQueue) === 1) {
79+
if (\count($this->promiseQueue) === 1) {
8080
$this->scheduleDispatch();
8181
}
8282
}
@@ -95,7 +95,7 @@ function (callable $resolve, callable $reject) use ($key) {
9595
public function loadMany(array $keys)
9696
{
9797
return \React\Promise\all(
98-
array_map(
98+
\array_map(
9999
function ($key) {
100100
return $this->load($key);
101101
},
@@ -187,17 +187,17 @@ private function dispatchQueue()
187187
*/
188188
private function dispatchQueueBatch($batch)
189189
{
190-
$keys = array_column($batch, 'key');
190+
$keys = \array_column($batch, 'key');
191191
$batchLoadFunction = $this->batchLoadFunction;
192192

193193
/** @var Promise $batchPromise */
194194
$batchPromise = $batchLoadFunction($keys);
195195

196-
if (! $batchPromise || ! is_callable([$batchPromise, 'then'])) {
196+
if (! $batchPromise || ! \is_callable([$batchPromise, 'then'])) {
197197
return $this->handleFailedDispatch($batch, new DataLoaderException(
198198
self::class . ' must be constructed with a function which accepts ' .
199199
'an array of keys and returns a Promise which resolves to an array of values ' .
200-
sprintf('not return a Promise: %s.', gettype($batchPromise))
200+
\sprintf('not return a Promise: %s.', \gettype($batchPromise))
201201
));
202202
}
203203

@@ -221,11 +221,11 @@ function ($values) use ($batch, $keys) {
221221
*/
222222
private function dispatchQueueInMultipleBatches(array $queue, $maxBatchSize)
223223
{
224-
$numberOfBatchesToDispatch = count($queue) / $maxBatchSize;
224+
$numberOfBatchesToDispatch = \count($queue) / $maxBatchSize;
225225

226226
for ($i = 0; $i < $numberOfBatchesToDispatch; $i++) {
227227
$this->dispatchQueueBatch(
228-
array_slice($queue, $i * $maxBatchSize, $maxBatchSize)
228+
\array_slice($queue, $i * $maxBatchSize, $maxBatchSize)
229229
);
230230
}
231231
}
@@ -271,20 +271,20 @@ private function handleFailedDispatch(array $batch, \Exception $error)
271271
*/
272272
private function validateBatchPromiseOutput($values, $keys)
273273
{
274-
if (! is_array($values)) {
274+
if (! \is_array($values)) {
275275
throw new DataLoaderException(
276276
self::class . ' must be constructed with a function which accepts ' .
277277
'an array of keys and returns a Promise which resolves to an array of values ' .
278-
sprintf('not return a Promise: %s.', gettype($values))
278+
\sprintf('not return a Promise: %s.', \gettype($values))
279279
);
280280
}
281281

282-
if (count($values) !== count($keys)) {
282+
if (\count($values) !== \count($keys)) {
283283
throw new DataLoaderException(
284284
self::class . ' must be constructed with a function which accepts ' .
285285
'an array of keys and returns a Promise which resolves to an array of values, but ' .
286286
'the function did not return a Promise of an array of the same length as the array of keys.' .
287-
sprintf("\n Keys: %s\n Values: %s\n", count($keys), count($values))
287+
\sprintf("\n Keys: %s\n Values: %s\n", \count($keys), \count($values))
288288
);
289289
}
290290
}

src/DataLoaderOptions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private function validateOptions($maxBatchSize, $shouldBatch, $shouldCache)
8080
*/
8181
private function validateBatchOption($shouldBatch)
8282
{
83-
if (!is_bool($shouldBatch)) {
83+
if (!\is_bool($shouldBatch)) {
8484
throw new \InvalidArgumentException('Expected argument $shouldBatch to be a boolean');
8585
}
8686
}
@@ -90,7 +90,7 @@ private function validateBatchOption($shouldBatch)
9090
*/
9191
private function validateCacheOption($shouldCache)
9292
{
93-
if (!is_bool($shouldCache)) {
93+
if (!\is_bool($shouldCache)) {
9494
throw new \InvalidArgumentException('Expected argument $shouldCache to be a boolean');
9595
}
9696
}
@@ -100,7 +100,7 @@ private function validateCacheOption($shouldCache)
100100
*/
101101
private function validateMaxBatchSizeOption($maxBatchSize)
102102
{
103-
if ($maxBatchSize !== null && !is_int($maxBatchSize)) {
103+
if ($maxBatchSize !== null && !\is_int($maxBatchSize)) {
104104
throw new \InvalidArgumentException('Expected argument $maxBatchSize to be null or an integer');
105105
}
106106
}

0 commit comments

Comments
 (0)