From fa02e7d8cd6b414fbbb94a683dcfecb6636485f3 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 16 Jan 2020 22:03:48 +0000 Subject: [PATCH] Migration: add collection element caching to MigrationResolutionHooksImpl. This should make the fix builder faster, since TypedLiteralResolver has to query the elements of various collections multiple times. Change-Id: If49317b8e095b49b693e8a4885914a631efd6d2e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/131844 Reviewed-by: Mike Fairhurst --- pkg/nnbd_migration/lib/src/fix_builder.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/nnbd_migration/lib/src/fix_builder.dart b/pkg/nnbd_migration/lib/src/fix_builder.dart index ebf383d43f9..fd486b8878c 100644 --- a/pkg/nnbd_migration/lib/src/fix_builder.dart +++ b/pkg/nnbd_migration/lib/src/fix_builder.dart @@ -192,6 +192,8 @@ class FixBuilder { class MigrationResolutionHooksImpl implements MigrationResolutionHooks { final FixBuilder _fixBuilder; + final Expando> _collectionElements = Expando(); + FlowAnalysis _flowAnalysis; @@ -240,7 +242,7 @@ class MigrationResolutionHooksImpl implements MigrationResolutionHooks { @override List getListElements(ListLiteral node) { - return node.elements + return _collectionElements[node] ??= node.elements .map(_transformCollectionElement) .where((e) => e != null) .toList(); @@ -254,7 +256,7 @@ class MigrationResolutionHooksImpl implements MigrationResolutionHooks { @override List getSetOrMapElements(SetOrMapLiteral node) { - return node.elements + return _collectionElements[node] ??= node.elements .map(_transformCollectionElement) .where((e) => e != null) .toList();