From 204cd3a11c262f8e42c99e7f1fdfefb3c4cbf1a9 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 25 Jan 2023 17:05:06 +0300 Subject: [PATCH] [#31] fstree: Optimize `treePath` Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/blobstor/fstree/fstree.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/local_object_storage/blobstor/fstree/fstree.go b/pkg/local_object_storage/blobstor/fstree/fstree.go index 14d1db3415..7dd8ca3da5 100644 --- a/pkg/local_object_storage/blobstor/fstree/fstree.go +++ b/pkg/local_object_storage/blobstor/fstree/fstree.go @@ -172,17 +172,19 @@ func (t *FSTree) iterate(depth uint64, curPath []string, prm common.IteratePrm) func (t *FSTree) treePath(addr oid.Address) string { sAddr := stringifyAddress(addr) - dirs := make([]string, 0, t.Depth+1+1) // 1 for root, 1 for file - dirs = append(dirs, t.RootPath) + var sb strings.Builder + sb.Grow(len(t.RootPath) + len(sAddr) + int(t.Depth) + 1) + sb.WriteString(t.RootPath) for i := 0; uint64(i) < t.Depth; i++ { - dirs = append(dirs, sAddr[:t.DirNameLen]) + sb.WriteRune(filepath.Separator) + sb.WriteString(sAddr[:t.DirNameLen]) sAddr = sAddr[t.DirNameLen:] } - dirs = append(dirs, sAddr) - - return filepath.Join(dirs...) + sb.WriteRune(filepath.Separator) + sb.WriteString(sAddr) + return sb.String() } // Delete removes the object with the specified address from the storage.