-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: using slices.Contains to simplify the code #6234
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,13 @@ | |
"net" | ||
"net/http" | ||
"runtime" | ||
"slices" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/algorand/go-deadlock" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that dropping this import is why you're getting the |
||
"github.com/algorand/websocket" | ||
|
||
"github.com/algorand/go-algorand/config" | ||
|
@@ -52,13 +52,7 @@ | |
const msgsInReadBufferPerPeer = 10 | ||
|
||
func init() { | ||
matched := false | ||
for _, version := range SupportedProtocolVersions { | ||
if version == versionPeerFeatures { | ||
matched = true | ||
} | ||
} | ||
if !matched { | ||
if !slices.Contains(SupportedProtocolVersions, versionPeerFeatures) { | ||
panic(fmt.Sprintf("peer features version %s is not supported %v", versionPeerFeatures, SupportedProtocolVersions)) | ||
} | ||
|
||
|
@@ -252,7 +246,7 @@ | |
responseChannels map[uint64]chan *Response | ||
|
||
// responseChannelsMutex guards the operations of responseChannels | ||
responseChannelsMutex deadlock.RWMutex | ||
Check failure on line 249 in network/wsPeer.go GitHub Actions / reviewdog-errors
Check failure on line 249 in network/wsPeer.go GitHub Actions / reviewdog-errors
Check failure on line 249 in network/wsPeer.go GitHub Actions / Performance regression check
|
||
|
||
// sendMessageTag is a map of allowed message to send to a peer. We don't use any synchronization on this map, and the | ||
// only guarantee is that it's being accessed only during startup and/or by the sending loop go routine. | ||
|
@@ -278,12 +272,12 @@ | |
clientDataStore map[string]interface{} | ||
|
||
// clientDataStoreMu synchronizes access to clientDataStore | ||
clientDataStoreMu deadlock.Mutex | ||
Check failure on line 275 in network/wsPeer.go GitHub Actions / reviewdog-errors
Check failure on line 275 in network/wsPeer.go GitHub Actions / reviewdog-errors
Check failure on line 275 in network/wsPeer.go GitHub Actions / Performance regression check
|
||
|
||
// closers is a slice of functions to run when the peer is closed | ||
closers []func() | ||
// closersMu synchronizes access to closers | ||
closersMu deadlock.RWMutex | ||
Check failure on line 280 in network/wsPeer.go GitHub Actions / reviewdog-errors
Check failure on line 280 in network/wsPeer.go GitHub Actions / Performance regression check
|
||
|
||
// peerType defines the peer's underlying connection type | ||
// used for separate p2p vs ws metrics | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
"math/rand" | ||
"os" | ||
"path/filepath" | ||
"slices" | ||
"sort" | ||
"strings" | ||
"time" | ||
|
@@ -1003,10 +1004,8 @@ func (pps *WorkerState) generateAccounts() { | |
} | ||
|
||
func uniqueAppend(they []string, x string) []string { | ||
for _, v := range they { | ||
if v == x { | ||
return they | ||
} | ||
if !slices.Contains(they, x) { | ||
return append(they, x) | ||
} | ||
return append(they, x) | ||
return they | ||
Comment on lines
+1007
to
+1010
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer swapping the |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful. The loop was iterating over
append(recordTypes, "")
. I guess blank matters here.