Skip to content

Commit

Permalink
Merge pull request #2364 from Haehnchen/feature/class-resolve
Browse files Browse the repository at this point in the history
cache resolved container classes to reduce wall time impact
  • Loading branch information
Haehnchen committed Apr 28, 2024
2 parents d5d5e1a + db88a0b commit 2e26bfb
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public static class ServiceCollector {

@Nullable
private Set<String> serviceNamesCache;
private Map<String, Set<String>> serviceClassNameCache;

private ServiceCollector(@NotNull Project project) {
this.project = project;
Expand Down Expand Up @@ -333,23 +334,25 @@ private Map<String, ContainerService> collectDecorated(@NotNull Collection<Servi
}

public Set<String> convertClassNameToServices(@NotNull String fqnClassName) {

Set<String> serviceNames = new HashSet<>();

fqnClassName = StringUtils.stripStart(fqnClassName, "\\");

for(Map.Entry<String, ContainerService> entry: this.getServices().entrySet()) {
for (String className : entry.getValue().getClassNames()) {
String indexedClassName = this.getParameterCollector().resolve(className);
if(indexedClassName != null) {
if(StringUtils.stripStart(indexedClassName, "\\").equalsIgnoreCase(fqnClassName)) {
serviceNames.add(entry.getKey());
if (this.serviceClassNameCache == null) {
Map<String, Set<String>> result = new HashMap<>();
for (Map.Entry<String, ContainerService> entry: this.getServices().entrySet()) {
for (String className : entry.getValue().getClassNames()) {
String indexedClassName = this.getParameterCollector().resolve(className);
if (indexedClassName != null) {
indexedClassName = "\\" + StringUtils.stripStart(indexedClassName, "\\");

result.putIfAbsent(indexedClassName, new HashSet<>());
result.get(indexedClassName).add(entry.getKey());
}
}
}

this.serviceClassNameCache = result;
}

return serviceNames;
fqnClassName = "\\" + StringUtils.stripStart(fqnClassName, "\\");
return this.serviceClassNameCache.getOrDefault(fqnClassName, Collections.emptySet());
}

private Set<String> getNames() {
Expand Down

0 comments on commit 2e26bfb

Please sign in to comment.