Skip to content

Commit 1dc8158

Browse files
authored
all: use slices.Contains ethereum#29459 (XinFinOrg#1177)
1 parent bf09334 commit 1dc8158

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

node/node.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"os"
2626
"path/filepath"
2727
"reflect"
28+
"slices"
2829
"strings"
2930
"sync"
3031

@@ -288,16 +289,6 @@ func (n *Node) openEndpoints() error {
288289
return err
289290
}
290291

291-
// containsLifecycle checks if 'lfs' contains 'l'.
292-
func containsLifecycle(lfs []Lifecycle, l Lifecycle) bool {
293-
for _, obj := range lfs {
294-
if obj == l {
295-
return true
296-
}
297-
}
298-
return false
299-
}
300-
301292
// stopServices terminates running services, RPC and p2p networking.
302293
// It is the inverse of Start.
303294
func (n *Node) stopServices(running []Lifecycle) error {
@@ -575,7 +566,7 @@ func (n *Node) RegisterLifecycle(lifecycle Lifecycle) {
575566
if n.state != initializingState {
576567
panic("can't register lifecycle on running/stopped node")
577568
}
578-
if containsLifecycle(n.lifecycles, lifecycle) {
569+
if slices.Contains(n.lifecycles, lifecycle) {
579570
panic(fmt.Sprintf("attempt to register lifecycle %T more than once", lifecycle))
580571
}
581572
n.lifecycles = append(n.lifecycles, lifecycle)

node/node_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net"
2424
"net/http"
2525
"reflect"
26+
"slices"
2627
"strings"
2728
"testing"
2829

@@ -116,7 +117,7 @@ func TestLifecycleRegistry_Successful(t *testing.T) {
116117
noop := NewNoop()
117118
stack.RegisterLifecycle(noop)
118119

119-
if !containsLifecycle(stack.lifecycles, noop) {
120+
if !slices.Contains(stack.lifecycles, Lifecycle(noop)) {
120121
t.Fatalf("lifecycle was not properly registered on the node, %v", err)
121122
}
122123
}

0 commit comments

Comments
 (0)