review: perf: reduce overhead of isLocalType check #4211
Merged
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.
Those are two very related performance improvements. While they aren't that significant, it might add up for larger projects.
When using
TypeFactory#get(String)
with a nested type, the method extracts the outer type string,get
s that type recursively and uses its reference to check if it is a local type. The implementation ofisLocalType
then accesses its type again and calls theisLocalType
method of the type. We can just skip this indirection by callingisLocalType
on the type directly.Previously, the
isLocalType
implementation of the reference accessed the declaration twice (= building the qualified name and passing it toTypeFactory#get(String)
as mentioned in 1.) This is only needed once, so we reuse the returned value.I also saw that if the declaration in 2. is
null
, there is a regex patternspoon/src/main/java/spoon/support/reflect/reference/CtTypeReferenceImpl.java
Lines 524 to 526 in d9bcb11
1LocalType1
would not be matched. I will address that separately.