Avoid comparing strings all time
This commit is contained in:

committed by
Andreas Dangel

parent
55b4d81fbf
commit
b6bc06d3d2
@ -299,7 +299,12 @@ public class TypeSet {
|
||||
*/
|
||||
public ImportOnDemandResolver(PMDASMClassLoader pmdClassLoader, Set<String> importStmts) {
|
||||
super(pmdClassLoader);
|
||||
this.importStmts = importStmts;
|
||||
this.importStmts = new HashSet<>();
|
||||
for (final String stmt : importStmts) {
|
||||
if (stmt.endsWith("*")) {
|
||||
this.importStmts.add(stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -309,15 +314,11 @@ public class TypeSet {
|
||||
}
|
||||
|
||||
for (String importStmt : importStmts) {
|
||||
if (importStmt.endsWith("*")) {
|
||||
final String fqClassName = new StringBuilder(importStmt.length() + name.length())
|
||||
.append(importStmt)
|
||||
.replace(importStmt.length() - 1, importStmt.length(), name)
|
||||
.toString();
|
||||
final Class<?> c = resolveMaybeInner(name, fqClassName);
|
||||
if (c != null) {
|
||||
return c;
|
||||
}
|
||||
final String fqClassName = new StringBuilder(importStmt.length() + name.length()).append(importStmt)
|
||||
.replace(importStmt.length() - 1, importStmt.length(), name).toString();
|
||||
final Class<?> c = resolveMaybeInner(name, fqClassName);
|
||||
if (c != null) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,20 +327,16 @@ public class TypeSet {
|
||||
|
||||
@Override
|
||||
public boolean couldResolve(String name) {
|
||||
for (String importStmt : importStmts) {
|
||||
if (importStmt.endsWith("*")) {
|
||||
final String fqClassName = new StringBuilder(importStmt.length() + name.length())
|
||||
.append(importStmt)
|
||||
.replace(importStmt.length() - 1, importStmt.length(), name)
|
||||
.toString();
|
||||
// can any class be resolved / was never attempted?
|
||||
if (super.couldResolve(fqClassName)) {
|
||||
return true;
|
||||
}
|
||||
for (String importStmt : importStmts) {
|
||||
final String fqClassName = new StringBuilder(importStmt.length() + name.length()).append(importStmt)
|
||||
.replace(importStmt.length() - 1, importStmt.length(), name).toString();
|
||||
// can any class be resolved / was never attempted?
|
||||
if (super.couldResolve(fqClassName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user