Skip to content

Commit 8a27373

Browse files
authored
Merge pull request #106 from tobyzerner/name-instance-cache
Reuse `Name` instances to improve performance
2 parents e5995e2 + cf0056b commit 8a27373

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Models/Naming/Name.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ class Name
5050
*/
5151
public string $element;
5252

53+
private static array $nameInstanceCache = [];
54+
5355
public static function forModel(object $model)
5456
{
55-
return static::build(get_class($model));
57+
$class = $model::class;
58+
59+
return static::$nameInstanceCache[$class] ??= static::build($class);
5660
}
5761

5862
public static function build(string $className)

0 commit comments

Comments
 (0)