Skip to content

Commit

Permalink
Optimise
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Jan 29, 2019
1 parent d6a56f2 commit 919dabc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ public static function component(DispatchableComponent $component)
if($dispatch)
{
$maxPrefix = $maxAlias = '';
$prefixLen = 0;
foreach($dispatch->getComponentAliases() as $alias => $namespace)
{
$trimNs = ltrim($namespace, '\\');
$prefix = Strings::commonPrefix($class, $trimNs);
if(substr($prefix, 0, strlen($trimNs)) === $trimNs && strlen($prefix) > strlen($maxPrefix))
$len = strlen($trimNs);
if(Strings::startsWith($class, $trimNs) && $len > $prefixLen)
{
$maxPrefix = $prefix;
$maxPrefix = $trimNs;
$prefixLen = $len;
$maxAlias = $alias;
}
}
Expand Down

0 comments on commit 919dabc

Please sign in to comment.