From 4bcfcd5cc8972b723e006e7ebc8c13cb6f4373fe Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Fri, 6 Apr 2018 11:29:25 +0200 Subject: [PATCH] added comments and got rid of fixed variable --- Gopkg.lock | 2 +- types/store.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 50a17e1fb9..2de9e117ef 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -458,6 +458,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "ed1f3f7f1728cd02945f90ca780e9bdc982573a36a5cc8d7e9f19fb40ba2ca19" + inputs-digest = "67298e1f8058b85f082dbd32123f2779b11bda282616e595141dba41a8675c39" solver-name = "gps-cdcl" solver-version = 1 diff --git a/types/store.go b/types/store.go index 9034e79307..7b73570cac 100644 --- a/types/store.go +++ b/types/store.go @@ -231,7 +231,9 @@ func (key *KVStoreKey) String() string { return fmt.Sprintf("KVStoreKey{%p, %s}", key, key.name) } -// TODO: Move to TmLibs +// PrefixEndBytes returns the []byte that would end a +// range query for all []byte with a certain prefix +// Deals with last byte of prefix being FF without overflowing func PrefixEndBytes(prefix []byte) []byte { if prefix == nil { return nil @@ -239,17 +241,16 @@ func PrefixEndBytes(prefix []byte) []byte { end := make([]byte, len(prefix)) copy(end, prefix) - finished := false - for !finished { + for { if end[len(end)-1] != byte(255) { end[len(end)-1]++ - finished = true + break } else { end = end[:len(end)-1] if len(end) == 0 { end = nil - finished = true + break } } }