mirror of https://github.com/Hilbis/Hilbish
perf: reslice listener slice instead of trying to do ordered move with append
parent
e4110fa4bc
commit
d6a86b0829
|
@ -107,7 +107,7 @@ func (b *Bait) Off(event string, listener *Listener) {
|
|||
|
||||
for i, handle := range handles {
|
||||
if handle == listener {
|
||||
b.handlers[event] = append(handles[:i], handles[i + 1:]...)
|
||||
b.removeListener(event, i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +146,13 @@ func (b *Bait) addListener(event string, listener *Listener) {
|
|||
b.handlers[event] = append(b.handlers[event], listener)
|
||||
}
|
||||
|
||||
|
||||
func (b *Bait) removeListener(event string, idx int) {
|
||||
b.handlers[event][idx] = b.handlers[event][len(b.handlers[event]) - 1]
|
||||
|
||||
b.handlers[event] = b.handlers[event][:len(b.handlers[event]) - 1]
|
||||
}
|
||||
|
||||
func (b *Bait) callRecoverer(event string, handler *Listener, err interface{}) {
|
||||
if b.recoverer == nil {
|
||||
panic(err)
|
||||
|
@ -241,7 +248,6 @@ func (b *Bait) bcatchOnce(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// todo: add once
|
||||
b.OnceLua(name, catcher)
|
||||
|
||||
return c.Next(), nil
|
||||
|
|
Loading…
Reference in New Issue