From fe3ffd1545992af9252eb17b99a5a43b672bb3e0 Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 16 Feb 2024 12:14:05 -0800 Subject: [PATCH] Use IsEmpty rather than nullcheck for scbus types * Use IsEmpty rather than nullcheck for scbus types --- wavesrv/pkg/scbus/modelupdate.go | 11 +++++++---- wavesrv/pkg/scbus/scbus.go | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/wavesrv/pkg/scbus/modelupdate.go b/wavesrv/pkg/scbus/modelupdate.go index 4e6f3605..0917f1aa 100644 --- a/wavesrv/pkg/scbus/modelupdate.go +++ b/wavesrv/pkg/scbus/modelupdate.go @@ -72,16 +72,16 @@ func (*ModelUpdatePacketType) GetType() string { return ModelUpdateStr } -func (mu *ModelUpdatePacketType) IsEmpty() bool { - if mu == nil || mu.Data == nil { +func (upk *ModelUpdatePacketType) IsEmpty() bool { + if upk == nil { return true } - return mu.Data.IsEmpty() + return upk.Data.IsEmpty() } // Clean the ClientData in an update, if present func (upk *ModelUpdatePacketType) Clean() { - if upk == nil || upk.Data == nil { + if upk.IsEmpty() { return } for _, item := range *(upk.Data) { @@ -106,6 +106,9 @@ func MakeUpdatePacket() *ModelUpdatePacketType { // Returns the items in the update that are of type I func GetUpdateItems[I ModelUpdateItem](upk *ModelUpdatePacketType) []*I { + if upk.IsEmpty() { + return nil + } ret := make([]*I, 0) for _, item := range *(upk.Data) { if i, ok := (item).(I); ok { diff --git a/wavesrv/pkg/scbus/scbus.go b/wavesrv/pkg/scbus/scbus.go index 7ce8d254..f9cefe29 100644 --- a/wavesrv/pkg/scbus/scbus.go +++ b/wavesrv/pkg/scbus/scbus.go @@ -110,7 +110,7 @@ func MakeUpdateBus() *UpdateBus { // Send an update to all channels in the collection func (bus *UpdateBus) DoUpdate(update UpdatePacket) { - if update == nil || update.IsEmpty() { + if update.IsEmpty() { return } update.Clean() @@ -128,7 +128,7 @@ func (bus *UpdateBus) DoUpdate(update UpdatePacket) { // Send a model update to only clients that are subscribed to the given screenId func (bus *UpdateBus) DoScreenUpdate(screenId string, update UpdatePacket) { - if update == nil { + if update.IsEmpty() { return } update.Clean()