From f22bcc829a06a76f9a1d4b67a221d3f0195dfb91 Mon Sep 17 00:00:00 2001 From: Gold872 Date: Sun, 17 Dec 2023 20:36:35 -0500 Subject: [PATCH] Minor performance improvements --- lib/services/nt_connection.dart | 6 +----- lib/widgets/nt_widgets/multi-topic/field_widget.dart | 2 +- lib/widgets/nt_widgets/nt_widget.dart | 4 +++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/services/nt_connection.dart b/lib/services/nt_connection.dart index 7730f8db..19738e92 100644 --- a/lib/services/nt_connection.dart +++ b/lib/services/nt_connection.dart @@ -155,11 +155,7 @@ class NTConnection { } Object? getLastAnnouncedValue(String topic) { - if (_ntClient.lastAnnouncedValues.containsKey(topic)) { - return _ntClient.lastAnnouncedValues[topic]; - } - - return null; + return _ntClient.lastAnnouncedValues[topic]; } void unpublishTopic(NT4Topic topic) { diff --git a/lib/widgets/nt_widgets/multi-topic/field_widget.dart b/lib/widgets/nt_widgets/multi-topic/field_widget.dart index e7391a0d..942f7aec 100644 --- a/lib/widgets/nt_widgets/multi-topic/field_widget.dart +++ b/lib/widgets/nt_widgets/multi-topic/field_widget.dart @@ -382,7 +382,7 @@ class FieldWidget extends NTWidget { List currentData = getCurrentData(); - if (!(const DeepCollectionEquality().equals(previousData, currentData))) { + if (!NTWidget.listEquals(previousData, currentData)) { yield Object(); previousData = currentData; } else if (!rendered) { diff --git a/lib/widgets/nt_widgets/nt_widget.dart b/lib/widgets/nt_widgets/nt_widget.dart index 63c050e6..638ed0e5 100644 --- a/lib/widgets/nt_widgets/nt_widget.dart +++ b/lib/widgets/nt_widgets/nt_widget.dart @@ -168,6 +168,8 @@ abstract class NTWidget extends StatelessWidget { }); } + static final Function listEquals = const DeepCollectionEquality().equals; + @protected List getCurrentData() { return []; @@ -180,7 +182,7 @@ abstract class NTWidget extends StatelessWidget { while (true) { List currentData = getCurrentData(); - if (!(const DeepCollectionEquality().equals(previousData, currentData))) { + if (!listEquals(previousData, currentData)) { yield Object(); previousData = currentData; }