From 3c8221f43fc45c02ff5efb8ba0f2de7ef490eee0 Mon Sep 17 00:00:00 2001 From: tiny-craft <137850705+tiny-craft@users.noreply.github.com> Date: Wed, 16 Aug 2023 10:15:17 +0800 Subject: [PATCH] perf: use build-in min/max function instead --- backend/services/connection_service.go | 3 +-- backend/utils/math/math_util.go | 10 ---------- frontend/src/components/dialogs/PreferencesDialog.vue | 4 ++-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go index cb08ba1..89ad6b6 100644 --- a/backend/services/connection_service.go +++ b/backend/services/connection_service.go @@ -12,7 +12,6 @@ import ( . "tinyrdm/backend/storage" "tinyrdm/backend/types" maputil "tinyrdm/backend/utils/map" - mathutil "tinyrdm/backend/utils/math" redis2 "tinyrdm/backend/utils/redis" ) @@ -1049,7 +1048,7 @@ func (c *connectionService) GetCmdHistory(pageNo, pageSize int) (resp types.JSRe } else { total := len(c.cmdHistory) startIndex := total / pageSize * (pageNo - 1) - endIndex := mathutil.Min(startIndex+pageSize, total) + endIndex := min(startIndex+pageSize, total) resp.Data = map[string]any{ "list": c.cmdHistory[startIndex:endIndex], "pageNo": pageNo, diff --git a/backend/utils/math/math_util.go b/backend/utils/math/math_util.go index b250dcf..d6848d2 100644 --- a/backend/utils/math/math_util.go +++ b/backend/utils/math/math_util.go @@ -20,11 +20,6 @@ func MaxWithIndex[T Hashable](items ...T) (T, int) { return items[selIndex], selIndex } -func Max[T Hashable](items ...T) T { - val, _ := MaxWithIndex(items...) - return val -} - // MinWithIndex 查找所有元素中的最小值 func MinWithIndex[T Hashable](items ...T) (T, int) { selIndex := -1 @@ -40,11 +35,6 @@ func MinWithIndex[T Hashable](items ...T) (T, int) { return items[selIndex], selIndex } -func Min[T Hashable](items ...T) T { - val, _ := MinWithIndex(items...) - return val -} - // Clamp 返回限制在minVal和maxVal范围内的value func Clamp[T Hashable](value T, minVal T, maxVal T) T { if minVal > maxVal { diff --git a/frontend/src/components/dialogs/PreferencesDialog.vue b/frontend/src/components/dialogs/PreferencesDialog.vue index 843b6ae..efff4ca 100644 --- a/frontend/src/components/dialogs/PreferencesDialog.vue +++ b/frontend/src/components/dialogs/PreferencesDialog.vue @@ -1,5 +1,5 @@