Skip to content

Commit

Permalink
Usage of count() in for cycles removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Mar 11, 2024
1 parent 157f7f1 commit 9df60a6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Views/ArrayView.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public function subview($selector, bool $readonly = null): ArrayViewInterface
*/
public function apply(callable $mapper): self
{
for ($i = 0; $i < \count($this); $i++) {
$size = \count($this);
for ($i = 0; $i < $size; $i++) {
/** @var T $item */
$item = $this[$i];
$this[$i] = $mapper($item, $i);
Expand All @@ -151,7 +152,8 @@ public function applyWith($data, callable $mapper): self

$dataView = ArrayView::toView($data);

for ($i = 0; $i < \count($this); $i++) {
$size = \count($this);
for ($i = 0; $i < $size; $i++) {
/** @var T $lhs */
$lhs = $this[$i];
/** @var U $rhs */
Expand All @@ -170,7 +172,8 @@ public function applyWith($data, callable $mapper): self
public function set($newValues): self
{
if (!\is_array($newValues) && !($newValues instanceof ArrayViewInterface)) {
for ($i = 0; $i < \count($this); $i++) {
$size = \count($this);
for ($i = 0; $i < $size; $i++) {
$this[$i] = $newValues;
}
return $this;
Expand All @@ -183,7 +186,8 @@ public function set($newValues): self

$newValuesView = ArrayView::toView($newValues);

for ($i = 0; $i < \count($this); $i++) {
$size = \count($this);
for ($i = 0; $i < $size; $i++) {
$this[$i] = $newValuesView[$i];
}

Expand All @@ -195,7 +199,8 @@ public function set($newValues): self
*/
public function getIterator(): \Generator
{
for ($i = 0; $i < \count($this); $i++) {
$size = \count($this);
for ($i = 0; $i < $size; $i++) {
/** @var T $item */
$item = $this[$i];
yield $item;
Expand Down

0 comments on commit 9df60a6

Please sign in to comment.