From 96aa0b69063599d9a40007ded8ff8edbc538d50e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 15 Jul 2021 22:53:12 +0300 Subject: [PATCH] store/memory: fix List Signed-off-by: Vasiliy Tolstov --- store/memory.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/store/memory.go b/store/memory.go index 94e38438..79a78293 100644 --- a/store/memory.go +++ b/store/memory.go @@ -70,19 +70,19 @@ func (m *memoryStore) delete(prefix, key string) { func (m *memoryStore) list(prefix string, limit, offset uint) []string { allItems := m.store.Items() - allKeys := make([]string, len(allItems)) - i := 0 + allKeys := make([]string, 0, len(allItems)) for k := range allItems { if !strings.HasPrefix(k, prefix) { continue } - allKeys[i] = strings.TrimPrefix(k, prefix) - if allKeys[i][0] == '/' { - allKeys[i] = allKeys[i][1:] + k = strings.TrimPrefix(k, prefix) + if k[0] == '/' { + k = k[1:] } - i++ + allKeys = append(allKeys, k) } + if limit != 0 || offset != 0 { sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) sort.Slice(allKeys, func(i, j int) bool { return allKeys[i] < allKeys[j] }) @@ -99,7 +99,6 @@ func (m *memoryStore) list(prefix string, limit, offset uint) []string { } return allKeys[offset:end] } - return allKeys }