event: refactor to use slices.Delete in golang std lib

This commit is contained in:
cuiweixie 2025-08-12 10:55:04 +08:00
parent cbbf686ecc
commit c2f0df8372

View file

@ -21,6 +21,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"reflect" "reflect"
"slices"
"sync" "sync"
"time" "time"
) )
@ -122,7 +123,7 @@ func (mux *TypeMux) del(s *TypeMuxSubscription) {
if len(subs) == 1 { if len(subs) == 1 {
delete(mux.subm, typ) delete(mux.subm, typ)
} else { } else {
mux.subm[typ] = posdelete(subs, pos) mux.subm[typ] = slices.Delete(slices.Clone(subs), pos, pos+1)
} }
} }
} }
@ -137,13 +138,6 @@ func find(slice []*TypeMuxSubscription, item *TypeMuxSubscription) int {
return -1 return -1
} }
func posdelete(slice []*TypeMuxSubscription, pos int) []*TypeMuxSubscription {
news := make([]*TypeMuxSubscription, len(slice)-1)
copy(news[:pos], slice[:pos])
copy(news[pos:], slice[pos+1:])
return news
}
// TypeMuxSubscription is a subscription established through TypeMux. // TypeMuxSubscription is a subscription established through TypeMux.
type TypeMuxSubscription struct { type TypeMuxSubscription struct {
mux *TypeMux mux *TypeMux