From 5db3b5fb8bb23b527ab58d06ed5628c943e69a0b Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 18 Nov 2023 23:23:01 -0300 Subject: [PATCH] use binary search in RestrictToSpecifiedKinds() --- plugins/events.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/events.go b/plugins/events.go index 78711bd..bc3de0a 100644 --- a/plugins/events.go +++ b/plugins/events.go @@ -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"