mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-04-07 11:28:02 +02:00
use binary search in RestrictToSpecifiedKinds()
This commit is contained in:
parent
dcdf86c4e4
commit
5db3b5fb8b
@ -64,9 +64,7 @@ func PreventLargeTags(maxTagValueLen int) func(context.Context, *nostr.Event) (b
|
||||
func RestrictToSpecifiedKinds(kinds ...uint16) func(context.Context, *nostr.Event) (bool, string) {
|
||||
max := 0
|
||||
min := 0
|
||||
allowed := make(map[uint16]struct{}, len(kinds))
|
||||
for _, kind := range kinds {
|
||||
allowed[kind] = struct{}{}
|
||||
if int(kind) > max {
|
||||
max = int(kind)
|
||||
}
|
||||
@ -86,7 +84,7 @@ func RestrictToSpecifiedKinds(kinds ...uint16) func(context.Context, *nostr.Even
|
||||
}
|
||||
|
||||
// hopefully this map of uint16s is very fast
|
||||
if _, allowed := allowed[uint16(event.Kind)]; allowed {
|
||||
if _, allowed := slices.BinarySearch(kinds, uint16(event.Kind)); allowed {
|
||||
return false, ""
|
||||
}
|
||||
return true, "event kind not allowed"
|
||||
|
Loading…
x
Reference in New Issue
Block a user