Skip to content

Commit

Permalink
Tune ImportLayoutStyle
Browse files Browse the repository at this point in the history
Small performance tweaks.
  • Loading branch information
knutwannheden committed May 1, 2024
1 parent 88d9bc9 commit ba548dc
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ public boolean isPackageFoldable(String packageName) {

private void setJVMClassNames() {
for (JavaType.FullyQualified fqn : classpath) {
if ("java.lang".equals(fqn.getPackageName())) {
// first check `getFullyQualifiedName()` to avoid unnecessary allocations
if (fqn.getFullyQualifiedName().startsWith("java.lang.") && "java.lang".equals(fqn.getPackageName())) {
jvmClasspathNames.add(fqn.getClassName());
}
}
Expand All @@ -554,32 +555,26 @@ private Map<String, Set<String>> mapNamesInPackageToPackages() {

for (JRightPadded<J.Import> anImport : originalImports) {
checkPackageForClasses.add(packageOrOuterClassName(anImport));
nameToPackages.computeIfAbsent(anImport.getElement().getClassName(), p -> new HashSet<>())
nameToPackages.computeIfAbsent(anImport.getElement().getClassName(), p -> new HashSet<>(3))
.add(anImport.getElement().getPackageName());
}

for (JavaType.FullyQualified classGraphFqn : classpath) {
String packageName = classGraphFqn.getPackageName();
if (checkPackageForClasses.contains(packageName)) {
String className = classGraphFqn.getClassName();
Set<String> packages = nameToPackages.getOrDefault(className, new HashSet<>());
packages.add(packageName);
nameToPackages.put(className, packages);
nameToPackages.computeIfAbsent(className, p -> new HashSet<>(3)).add(packageName);
} else if (checkPackageForClasses.contains(classGraphFqn.getFullyQualifiedName())) {
packageName = classGraphFqn.getFullyQualifiedName();
for (JavaType.Variable member : classGraphFqn.getMembers()) {
if (member.getFlags().contains(Flag.Static)) {
Set<String> packages = nameToPackages.getOrDefault(member.getName(), new HashSet<>());
packages.add(packageName);
nameToPackages.put(member.getName(), packages);
if (member.hasFlags(Flag.Static)) {
nameToPackages.computeIfAbsent(member.getName(), p -> new HashSet<>(3)).add(packageName);
}
}

for (JavaType.Method method : classGraphFqn.getMethods()) {
if (method.getFlags().contains(Flag.Static)) {
Set<String> packages = nameToPackages.getOrDefault(method.getName(), new HashSet<>());
packages.add(packageName);
nameToPackages.put(method.getName(), packages);
if (method.hasFlags(Flag.Static)) {
nameToPackages.computeIfAbsent(method.getName(), p -> new HashSet<>(3)).add(packageName);
}
}
}
Expand Down

0 comments on commit ba548dc

Please sign in to comment.