-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: reduce number of calls to class autoloader during type parsing
This change aims to reduce the number of calls made to the global class autoloader, by limiting the class existence checks during type parsing.
- Loading branch information
Showing
8 changed files
with
67 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CuyZ\Valinor\Type\Parser\Lexer; | ||
|
||
use CuyZ\Valinor\Type\Parser\Lexer\Token\ClassNameToken; | ||
use CuyZ\Valinor\Type\Parser\Lexer\Token\EnumNameToken; | ||
use CuyZ\Valinor\Type\Parser\Lexer\Token\Token; | ||
use CuyZ\Valinor\Type\Parser\Lexer\Token\UnknownSymbolToken; | ||
use CuyZ\Valinor\Utility\Reflection\Reflection; | ||
use UnitEnum; | ||
|
||
/** @internal */ | ||
final class ObjectLexer implements TypeLexer | ||
{ | ||
public function tokenize(string $symbol): Token | ||
{ | ||
if (Reflection::enumExists($symbol)) { | ||
/** @var class-string<UnitEnum> $symbol */ | ||
return new EnumNameToken($symbol); | ||
} | ||
|
||
if (Reflection::classOrInterfaceExists($symbol)) { | ||
/** @var class-string $symbol */ | ||
return new ClassNameToken($symbol); | ||
} | ||
|
||
return new UnknownSymbolToken($symbol); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters