Repository navigation
Implement function discovery cache (fixes #5) - #11
Merged
Merged
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5
Description
Caches the function class discovery in
FunctionLoaderso repeatedload()calls skip filesystem scans andis_subclass_of()checks.array<string, list<class-string<XPathFunctionInterface>>>) keyed bydirectory+"\0"+namespace, so separate loader instances with the same configuration share the result. The"\0"separator cannot occur in paths or namespaces, so keys are unambiguous.FunctionLoader::clearCache()to reset the cache in tests or when the functions directory changes at runtime.protected discover(); the class is no longerfinalso tests can count discovery calls — the same trade-offExpressionNormalizeralready makes (issue Cache normalization results in ExpressionNormalizer #3).load()/discover()now carry precise@return list<class-string<...>>docblocks, verified by Psalm.clearCache().Tests
New
tests/Compiler/FunctionLoaderCacheTest.php(8 tests) with autoloadable fixtures undertests/Fixtures/FunctionLoader/Example/:load()on the same loader runs discovery only onceclearCache()forces re-discoveryclearCache(), then appears*Function.phpfiles implementingXPathFunctionInterfaceare discovered (excludesNotAFunction.php,IgnoredHelper.php,notes.md)Compiler/Functionsdirectory still loadsCountFunctionsetUp()/tearDown()reset the static cache so tests are order-independentCompatibility / Risks
Low, as anticipated in the issue:
load()signature and return type unchanged; public API stays backward compatible.clearCache()— irrelevant for CL runs, now documented in the README.Verification
composer test→ 65/65 passingcomposer psalm→ no errors