From f92c12855d7b19ed8467f7c18faf536ff78401ee Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Sun, 9 Jan 2022 17:32:56 +0700 Subject: [PATCH] Decompressor: fast .Count method(#226) --- compress/decompress.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/compress/decompress.go b/compress/decompress.go index c07ddf2e3..c6f4d4fdc 100644 --- a/compress/decompress.go +++ b/compress/decompress.go @@ -189,17 +189,7 @@ func (g *Getter) nextPattern() []byte { return g.pattern() } -func (d *Decompressor) Count() int { - //TODO: likely it can be optimized by don't decompress values, or even by storing count in file - counterGetter := d.MakeGetter() - word := make([]byte, 0, 64) - count := 0 - for counterGetter.HasNext() { - word, _ = counterGetter.Next(word[:0]) - count++ - } - return count -} +func (d *Decompressor) Count() int { return int(d.count) } // MakeGetter creates an object that can be used to access words in the decompressor's file // Getter is not thread-safe, but there can be multiple getters used simultaneously and concrently