Skip to content

Commit 9c77515

Browse files
committed
event: refactor to use slices.Delete in golang std lib
1 parent cbbf686 commit 9c77515

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

event/event.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"reflect"
24+
"slices"
2425
"sync"
2526
"time"
2627
)
@@ -122,7 +123,7 @@ func (mux *TypeMux) del(s *TypeMuxSubscription) {
122123
if len(subs) == 1 {
123124
delete(mux.subm, typ)
124125
} else {
125-
mux.subm[typ] = posdelete(subs, pos)
126+
mux.subm[typ] = slices.Delete(subs, pos, pos+1)
126127
}
127128
}
128129
}
@@ -137,13 +138,6 @@ func find(slice []*TypeMuxSubscription, item *TypeMuxSubscription) int {
137138
return -1
138139
}
139140

140-
func posdelete(slice []*TypeMuxSubscription, pos int) []*TypeMuxSubscription {
141-
news := make([]*TypeMuxSubscription, len(slice)-1)
142-
copy(news[:pos], slice[:pos])
143-
copy(news[pos:], slice[pos+1:])
144-
return news
145-
}
146-
147141
// TypeMuxSubscription is a subscription established through TypeMux.
148142
type TypeMuxSubscription struct {
149143
mux *TypeMux

0 commit comments

Comments
 (0)