Skip to content

Commit

Permalink
Optimize @configuration class parsing a little
Browse files Browse the repository at this point in the history
Update `ConfigurationClassParser` to skip `java.lang.annotation` types
which were often processed but would never provide useful results. Also
use a single shared immutable `SourceClass` instance to represent
`Object.class`.

Closes spring-projectsgh-22563
  • Loading branch information
philwebb committed Mar 13, 2019
1 parent 4780406 commit 1df95e1
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class ConfigurationClassParser {

private final DeferredImportSelectorHandler deferredImportSelectorHandler = new DeferredImportSelectorHandler();

private final SourceClass objectSourceClass = new SourceClass(Object.class);


/**
* Create a new {@link ConfigurationClassParser} instance that will be used
Expand Down Expand Up @@ -639,8 +641,8 @@ private SourceClass asSourceClass(ConfigurationClass configurationClass) throws
* Factory method to obtain a {@link SourceClass} from a {@link Class}.
*/
SourceClass asSourceClass(@Nullable Class<?> classType) throws IOException {
if (classType == null) {
return new SourceClass(Object.class);
if (classType == null || classType.getName().startsWith("java.lang.annotation")) {
return this.objectSourceClass;
}
try {
// Sanity test that we can reflectively read annotations,
Expand Down Expand Up @@ -671,8 +673,8 @@ private Collection<SourceClass> asSourceClasses(String... classNames) throws IOE
* Factory method to obtain a {@link SourceClass} from a class name.
*/
SourceClass asSourceClass(@Nullable String className) throws IOException {
if (className == null) {
return new SourceClass(Object.class);
if (className == null || className.startsWith("java.lang.annotation")) {
return this.objectSourceClass;
}
if (className.startsWith("java")) {
// Never use ASM for core java types
Expand Down

0 comments on commit 1df95e1

Please sign in to comment.