Skip to content

Commit ea22ecf

Browse files
author
larry.sulebalogun
committed
10 - Remove the two loop operation and use foreach for optimization
1 parent 6798533 commit ea22ecf

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Capability/Registry.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,19 @@ private function paginateResults(array $items, int $limit, ?string $cursor = nul
401401
}
402402
}
403403

404-
// Return slice of items starting from offset
405-
return array_values(\array_slice($items, $offset, $limit, true));
404+
$result = [];
405+
$count = 0;
406+
$currentIndex = 0;
407+
408+
foreach ($items as $item) {
409+
if ($currentIndex >= $offset && $count < $limit) {
410+
$result[] = $item;
411+
++$count;
412+
}
413+
++$currentIndex;
414+
}
415+
416+
return $result;
406417
}
407418

408419
/**

0 commit comments

Comments
 (0)