Skip to content

Commit

Permalink
optimize for loop in WildcardPermission (#2113)
Browse files Browse the repository at this point in the history
  • Loading branch information
SubhanSh authored Oct 23, 2022
1 parent 074382c commit e57a67b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/WildcardPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public function implies($permission): bool
$otherParts = $permission->getParts();

$i = 0;
$partsCount = $this->getParts()->count();
foreach ($otherParts as $otherPart) {
if ($this->getParts()->count() - 1 < $i) {
if ($partsCount - 1 < $i) {
return true;
}

Expand All @@ -60,7 +61,7 @@ public function implies($permission): bool
$i++;
}

for ($i; $i < $this->parts->count(); $i++) {
for ($i; $i < $partsCount; $i++) {
if (! $this->parts->get($i)->contains(static::WILDCARD_TOKEN)) {
return false;
}
Expand Down

0 comments on commit e57a67b

Please sign in to comment.