From 312cc32da517b290a09532e23a103745cb9f4cd4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 13 Nov 2025 16:18:49 -0300 Subject: [PATCH] nip77: one small useless optimization. --- nip77/negentropy/negentropy.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nip77/negentropy/negentropy.go b/nip77/negentropy/negentropy.go index 68ebf3d..89f034b 100644 --- a/nip77/negentropy/negentropy.go +++ b/nip77/negentropy/negentropy.go @@ -123,7 +123,8 @@ func (n *Negentropy) reconcileAux(reader *bytes.Reader) ([]byte, error) { var prevBound Bound prevIndex := 0 - skipping := false // this means we are currently coalescing ranges into skip + skipping := false // this means we are currently coalescing ranges into skip + var theirItems map[nostr.ID]struct{} // used to track stuff in IdListMode partialOutput := bytes.NewBuffer(make([]byte, 0, 100)) for reader.Len() > 0 { @@ -176,8 +177,13 @@ func (n *Negentropy) reconcileAux(reader *bytes.Reader) ([]byte, error) { return nil, fmt.Errorf("failed to decode number of ids: %w", err) } + if theirItems == nil { + theirItems = make(map[nostr.ID]struct{}, numIds) + } else { + clear(theirItems) // reusing this from the last run + } + // what they have - theirItems := make(map[nostr.ID]struct{}, numIds) for i := 0; i < numIds; i++ { var id [32]byte if _, err := reader.Read(id[:]); err != nil {