From 9df60a69e97010f046870b4760028fc82a9050df Mon Sep 17 00:00:00 2001 From: Smoren Date: Mon, 11 Mar 2024 08:46:24 +0300 Subject: [PATCH] Usage of count() in for cycles removed. --- src/Views/ArrayView.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Views/ArrayView.php b/src/Views/ArrayView.php index 9809387..6b3acac 100644 --- a/src/Views/ArrayView.php +++ b/src/Views/ArrayView.php @@ -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); @@ -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 */ @@ -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; @@ -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]; } @@ -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;