Skip to content

Commit

Permalink
perf: replace some slice utils with built-in utils
Browse files Browse the repository at this point in the history
  • Loading branch information
tiny-craft committed Jun 19, 2024
1 parent 6bd1b23 commit 65cfdd1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 338 deletions.
4 changes: 2 additions & 2 deletions backend/services/browser_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ func (b *browserService) OpenConnection(name string) (resp types.JSResp) {
selConn := Connection().getConnection(name)
// correct last database index
lastDB := selConn.LastDB
if selConn.DBFilterType == "show" && !sliceutil.Contains(selConn.DBFilterList, lastDB) {
if selConn.DBFilterType == "show" && !slices.Contains(selConn.DBFilterList, lastDB) {
lastDB = selConn.DBFilterList[0]
} else if selConn.DBFilterType == "hide" && sliceutil.Contains(selConn.DBFilterList, lastDB) {
} else if selConn.DBFilterType == "hide" && slices.Contains(selConn.DBFilterList, lastDB) {
lastDB = selConn.DBFilterList[0]
}
if lastDB != selConn.LastDB {
Expand Down
8 changes: 4 additions & 4 deletions backend/storage/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package storage
import (
"errors"
"gopkg.in/yaml.v3"
"slices"
"sync"
"tinyrdm/backend/consts"
"tinyrdm/backend/types"
sliceutil "tinyrdm/backend/utils/slice"
)

type ConnectionsStorage struct {
Expand Down Expand Up @@ -256,10 +256,10 @@ func (c *ConnectionsStorage) SaveSortedConnection(sortedConns types.Connections)

conns := c.GetConnectionsFlat()
takeConn := func(name string) (types.Connection, bool) {
idx, ok := sliceutil.Find(conns, func(i int) bool {
return conns[i].Name == name
idx := slices.IndexFunc(conns, func(connection types.Connection) bool {
return connection.Name == name
})
if ok {
if idx >= 0 {
ret := conns[idx]
conns = append(conns[:idx], conns[idx+1:]...)
return ret, true
Expand Down
Loading

0 comments on commit 65cfdd1

Please sign in to comment.