Skip to content

Commit

Permalink
perf: use build-in min/max function instead
Browse files Browse the repository at this point in the history
  • Loading branch information
tiny-craft committed Aug 16, 2023
1 parent 8bb6444 commit 3c8221f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
3 changes: 1 addition & 2 deletions backend/services/connection_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 0 additions & 10 deletions backend/utils/math/math_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/dialogs/PreferencesDialog.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { ref, watch } from 'vue'
import { ref, watch, nextTick } from 'vue'
import { useI18n } from 'vue-i18n'
import useDialog from 'stores/dialog'
import usePreferencesStore from 'stores/preferences.js'
Expand Down Expand Up @@ -34,7 +34,7 @@ watch(
() => dialogStore.preferencesDialogVisible,
(visible) => {
if (visible) {
nextTick().then(async () => initPreferences())
nextTick().then(initPreferences)
}
},
)
Expand Down

0 comments on commit 3c8221f

Please sign in to comment.