Skip to content

Commit db88a0b

Browse files
committed
cache resolved container classes to reduce wall time impact
1 parent d5d5e1a commit db88a0b

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/stubs/ContainerCollectionResolver.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public static class ServiceCollector {
156156

157157
@Nullable
158158
private Set<String> serviceNamesCache;
159+
private Map<String, Set<String>> serviceClassNameCache;
159160

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

335336
public Set<String> convertClassNameToServices(@NotNull String fqnClassName) {
336-
337-
Set<String> serviceNames = new HashSet<>();
338-
339-
fqnClassName = StringUtils.stripStart(fqnClassName, "\\");
340-
341-
for(Map.Entry<String, ContainerService> entry: this.getServices().entrySet()) {
342-
for (String className : entry.getValue().getClassNames()) {
343-
String indexedClassName = this.getParameterCollector().resolve(className);
344-
if(indexedClassName != null) {
345-
if(StringUtils.stripStart(indexedClassName, "\\").equalsIgnoreCase(fqnClassName)) {
346-
serviceNames.add(entry.getKey());
337+
if (this.serviceClassNameCache == null) {
338+
Map<String, Set<String>> result = new HashMap<>();
339+
for (Map.Entry<String, ContainerService> entry: this.getServices().entrySet()) {
340+
for (String className : entry.getValue().getClassNames()) {
341+
String indexedClassName = this.getParameterCollector().resolve(className);
342+
if (indexedClassName != null) {
343+
indexedClassName = "\\" + StringUtils.stripStart(indexedClassName, "\\");
344+
345+
result.putIfAbsent(indexedClassName, new HashSet<>());
346+
result.get(indexedClassName).add(entry.getKey());
347347
}
348348
}
349349
}
350+
351+
this.serviceClassNameCache = result;
350352
}
351353

352-
return serviceNames;
354+
fqnClassName = "\\" + StringUtils.stripStart(fqnClassName, "\\");
355+
return this.serviceClassNameCache.getOrDefault(fqnClassName, Collections.emptySet());
353356
}
354357

355358
private Set<String> getNames() {

0 commit comments

Comments
 (0)