From 6e3c7534523ca329c490a3ce2c7a033734636968 Mon Sep 17 00:00:00 2001 From: YaoZengzeng Date: Thu, 8 Aug 2019 09:41:03 +0800 Subject: [PATCH] refactor: reuse the slice in MemPostings.Delete() Signed-off-by: YaoZengzeng --- index/postings.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/index/postings.go b/index/postings.go index cef2d886..d9e9f81d 100644 --- a/index/postings.go +++ b/index/postings.go @@ -156,24 +156,11 @@ func (p *MemPostings) Delete(deleted map[uint64]struct{}) { } p.mtx.RUnlock() - // For each posting we first analyse whether the postings list is affected by the deletes. - // If yes, we actually reallocate a new postings list. for _, l := range vals { // Only lock for processing one postings list so we don't block reads for too long. p.mtx.Lock() - found := false - for _, id := range p.m[n][l] { - if _, ok := deleted[id]; ok { - found = true - break - } - } - if !found { - p.mtx.Unlock() - continue - } - repl := make([]uint64, 0, len(p.m[n][l])) + repl := p.m[n][l][:0] for _, id := range p.m[n][l] { if _, ok := deleted[id]; !ok {