From 5aa3defc671d98f35ef3612a5b4ba55e77e02d40 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 7 Jul 2022 15:56:05 +0300 Subject: [PATCH] [#1523] writecache: Remove `cloneBytes` Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/writecache/flush.go | 9 ++------- pkg/local_object_storage/writecache/get.go | 3 ++- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/local_object_storage/writecache/flush.go b/pkg/local_object_storage/writecache/flush.go index 0427b484f..162261fe4 100644 --- a/pkg/local_object_storage/writecache/flush.go +++ b/pkg/local_object_storage/writecache/flush.go @@ -4,6 +4,7 @@ import ( "time" "github.com/mr-tron/base58" + "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase" "github.com/nspcc-dev/neofs-sdk-go/object" @@ -84,7 +85,7 @@ func (c *cache) flush() { sz += len(k) + len(v) m = append(m, objectInfo{ addr: string(k), - data: cloneBytes(v), + data: slice.Copy(v), }) } return nil @@ -227,9 +228,3 @@ func (c *cache) flushObject(obj *object.Object) error { _, err = c.metabase.Put(pPrm) return err } - -func cloneBytes(a []byte) []byte { - b := make([]byte, len(a)) - copy(b, a) - return b -} diff --git a/pkg/local_object_storage/writecache/get.go b/pkg/local_object_storage/writecache/get.go index 951daad7e..6b18fea67 100644 --- a/pkg/local_object_storage/writecache/get.go +++ b/pkg/local_object_storage/writecache/get.go @@ -1,6 +1,7 @@ package writecache import ( + "github.com/nspcc-dev/neo-go/pkg/util/slice" "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common" apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status" objectSDK "github.com/nspcc-dev/neofs-sdk-go/object" @@ -66,7 +67,7 @@ func Get(db *bbolt.DB, key []byte) ([]byte, error) { return errNotFound } - value = cloneBytes(value) + value = slice.Copy(value) return nil }) return value, err