Skip to content

Commit

Permalink
Merge pull request #106 from tobyzerner/name-instance-cache
Browse files Browse the repository at this point in the history
Reuse `Name` instances to improve performance
  • Loading branch information
tonysm authored Apr 7, 2023
2 parents e5995e2 + cf0056b commit 8a27373
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Models/Naming/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ class Name
*/
public string $element;

private static array $nameInstanceCache = [];

public static function forModel(object $model)
{
return static::build(get_class($model));
$class = $model::class;

return static::$nameInstanceCache[$class] ??= static::build($class);
}

public static function build(string $className)
Expand Down

0 comments on commit 8a27373

Please sign in to comment.