refactor: use slices.Index/Delete and slices.Clone for small copies

This commit is contained in:
sam committed 2026-10-10 11:14:36 +11:00
1 parent c86368369f
commit 20d6ec93db
2 files changed
+8 -15

No files matched your search

+4 -6
View File
@@ -5,6 +5,7 @@
package events
import (
"slices"
"sync"
"sync/atomic"
"time"
@@ -234,12 +235,9 @@ func (b *Bus) Publish(e Event) {
func (b *Bus) unsubscribe(sub *Sub) {
b.mu.Lock()
defer b.mu.Unlock()
for i, s := range b.subs {
if s == sub {
b.subs = append(b.subs[:i], b.subs[i+1:]...)
close(s.c)
return
}
if i := slices.Index(b.subs, sub); i >= 0 {
b.subs = slices.Delete(b.subs, i, i+1)
close(sub.c)
}
}
+4 -9
View File
@@ -8,6 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
)
// JSONSchema represents a JSON Schema document describing a tool's input
@@ -169,17 +170,11 @@ func deepCopyAny(v any) any {
}
return out
case []string:
out := make([]string, len(val))
copy(out, val)
return out
return slices.Clone(val)
case []float64:
out := make([]float64, len(val))
copy(out, val)
return out
return slices.Clone(val)
case []bool:
out := make([]bool, len(val))
copy(out, val)
return out
return slices.Clone(val)
default:
return v
}