Don't use 'whereType' in NotImportedContributor.

Bug: https://github.com/dart-lang/sdk/issues/47680
Change-Id: I7e90f52e7658eef4b9280f485b457d86ac0f4e9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229820
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/not_imported_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/not_imported_contributor.dart
index d814bb5..8bbff4f 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/not_imported_contributor.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/not_imported_contributor.dart
@@ -92,7 +92,7 @@
       }
 
       extensionContributor.addExtensions(
-        exportElements.whereType<ExtensionElement>().toList(),
+        _extensions(exportElements),
       );
 
       builder.isNotImportedLibrary = false;
@@ -109,4 +109,17 @@
       }
     }
   }
+
+  /// This function intentionally does not use `whereType` for performance.
+  ///
+  /// https://github.com/dart-lang/sdk/issues/47680
+  static List<ExtensionElement> _extensions(List<Element> elements) {
+    var extensions = <ExtensionElement>[];
+    for (var element in elements) {
+      if (element is ExtensionElement) {
+        extensions.add(element);
+      }
+    }
+    return extensions;
+  }
 }