From 0854102ac47554d812ee15809bf925cce5b35d64 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Wed, 7 Feb 2024 13:32:35 -0600 Subject: [PATCH] Avoid dynamic Map/List invocations in ExportController (#7096) --- .../import_export/import_export.dart | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/devtools_app/lib/src/shared/config_specific/import_export/import_export.dart b/packages/devtools_app/lib/src/shared/config_specific/import_export/import_export.dart index 283e9b96cb2..d6b9482f261 100644 --- a/packages/devtools_app/lib/src/shared/config_specific/import_export/import_export.dart +++ b/packages/devtools_app/lib/src/shared/config_specific/import_export/import_export.dart @@ -46,8 +46,6 @@ class ImportController { // TODO(kenz): improve error handling here or in snapshot_screen.dart. void importData(DevToolsJsonFile jsonFile, {String? expectedScreenId}) { - final json = jsonFile.data; - // Do not allow two different imports within 500 ms of each other. This is a // workaround for the fact that we get two drop events for the same file. final now = DateTime.now(); @@ -60,6 +58,7 @@ class ImportController { } previousImportTime = now; + final json = jsonFile.data; final isDevToolsSnapshot = json is Map && json[DevToolsExportKeys.devToolsSnapshot.name] == true; if (!isDevToolsSnapshot) { @@ -97,18 +96,7 @@ enum ExportFileType { yaml; @override - String toString() { - switch (this) { - case json: - return 'json'; - case csv: - return 'csv'; - case yaml: - return 'yaml'; - default: - throw UnimplementedError('Unable to convert $this to a string'); - } - } + String toString() => name; } abstract class ExportController { @@ -169,11 +157,14 @@ abstract class ExportController { // with other trace viewers (catapult, perfetto, chrome://tracing), which // require a top level field named "traceEvents". if (activeScreenId == ScreenMetaData.performance.id) { - final traceEvents = List>.from( - contents[activeScreenId][traceEventsFieldName], - ); + final activeScreen = + (contents[activeScreenId] as Map).cast(); + final traceEvents = [ + for (final event in activeScreen[traceEventsFieldName] as List) + (event as Map).cast(), + ]; contents[traceEventsFieldName] = traceEvents; - contents[activeScreenId].remove(traceEventsFieldName); + activeScreen.remove(traceEventsFieldName); } return contents; }