Skip to content

Commit

Permalink
Avoid dynamic Map/List invocations in ExportController (flutter#7096)
Browse files Browse the repository at this point in the history
  • Loading branch information
srawlins authored Feb 7, 2024
1 parent 2791e14 commit 0854102
Showing 1 changed file with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -60,6 +58,7 @@ class ImportController {
}
previousImportTime = now;

final json = jsonFile.data;
final isDevToolsSnapshot = json is Map<String, dynamic> &&
json[DevToolsExportKeys.devToolsSnapshot.name] == true;
if (!isDevToolsSnapshot) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Map<String, dynamic>>.from(
contents[activeScreenId][traceEventsFieldName],
);
final activeScreen =
(contents[activeScreenId] as Map).cast<String, Object?>();
final traceEvents = [
for (final event in activeScreen[traceEventsFieldName] as List)
(event as Map).cast<String, Object?>(),
];
contents[traceEventsFieldName] = traceEvents;
contents[activeScreenId].remove(traceEventsFieldName);
activeScreen.remove(traceEventsFieldName);
}
return contents;
}
Expand Down

0 comments on commit 0854102

Please sign in to comment.