Improve performance of PluginLocator by caching results
R=scheglov@google.com
Review-Url: https://codereview.chromium.org/2754473005 .
diff --git a/pkg/analysis_server/lib/src/plugin/plugin_locator.dart b/pkg/analysis_server/lib/src/plugin/plugin_locator.dart
index 968ee53..85e3527 100644
--- a/pkg/analysis_server/lib/src/plugin/plugin_locator.dart
+++ b/pkg/analysis_server/lib/src/plugin/plugin_locator.dart
@@ -37,6 +37,8 @@
*/
final ResourceProvider resourceProvider;
+ final Map<String, String> pluginMap = <String, String>{};
+
/**
* Initialize a newly created plugin locator to use the given
* [resourceProvider] to access the file system.
@@ -56,6 +58,13 @@
* returning it.
*/
String findPlugin(String packageRoot) {
+ return pluginMap.putIfAbsent(packageRoot, () => _findPlugin(packageRoot));
+ }
+
+ /**
+ * The implementation of [findPlugin].
+ */
+ String _findPlugin(String packageRoot) {
Folder packageFolder = resourceProvider.getFolder(packageRoot);
File pubspecFile = packageFolder.getChildAssumingFile(pubspecFileName);
if (pubspecFile.exists) {