summaryrefslogtreecommitdiffstats
path: root/lib/db/namespaced.go
diff options
context:
space:
mode:
authorgreatroar <61184462+greatroar@users.noreply.github.com>2020-03-31 14:32:24 +0200
committerGitHub <noreply@github.com>2020-03-31 14:32:24 +0200
commit2f26a9597355d1795c6e2bee4b53bf16de9e301e (patch)
tree56d05ac1404607f66f4ad39d10c6a00a42236e4f /lib/db/namespaced.go
parent123941cf627ea9e4414dbd537d6331182b7730da (diff)
lib/db, lib/model: Code simplifications (#6484)
NamespacedKV.prefixedKey is still small enough to be inlined.
Diffstat (limited to 'lib/db/namespaced.go')
-rw-r--r--lib/db/namespaced.go11
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/db/namespaced.go b/lib/db/namespaced.go
index 18aaf292d3..285799c04c 100644
--- a/lib/db/namespaced.go
+++ b/lib/db/namespaced.go
@@ -17,20 +17,15 @@ import (
// a leveldb.
type NamespacedKV struct {
db *Lowlevel
- prefix []byte
+ prefix string
}
// NewNamespacedKV returns a new NamespacedKV that lives in the namespace
// specified by the prefix.
func NewNamespacedKV(db *Lowlevel, prefix string) *NamespacedKV {
- prefixBs := []byte(prefix)
- // After the conversion from string the cap will be larger than the len (in Go 1.11.5,
- // 32 bytes cap for small strings). We need to cut it down to ensure append() calls
- // on the prefix make a new allocation.
- prefixBs = prefixBs[:len(prefixBs):len(prefixBs)]
return &NamespacedKV{
db: db,
- prefix: prefixBs,
+ prefix: prefix,
}
}
@@ -130,7 +125,7 @@ func (n NamespacedKV) Delete(key string) error {
}
func (n NamespacedKV) prefixedKey(key string) []byte {
- return append(n.prefix, []byte(key)...)
+ return []byte(n.prefix + key)
}
// Well known namespaces that can be instantiated without knowing the key