From b4f3d1cf19721831dcef5096e500826a1f400410 Mon Sep 17 00:00:00 2001 From: Keegan Carruthers-Smith Date: Mon, 6 Nov 2023 12:14:31 +0200 Subject: [PATCH] build: use slices.Insert instead of several appends I found the code a bit hard to read before, this I believe is more clear. I was also hoping for an improvement in the benchmarks, but the improvement was statistically insignificant. Test Plan: go test --- build/ctags.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/build/ctags.go b/build/ctags.go index f5de181d..b2a2a3aa 100644 --- a/build/ctags.go +++ b/build/ctags.go @@ -22,6 +22,8 @@ import ( "sync" "time" + "golang.org/x/exp/slices" + "github.com/sourcegraph/zoekt" "github.com/sourcegraph/zoekt/ctags" ) @@ -151,17 +153,16 @@ func tagsToSections(content []byte, tags []*ctags.Entry) ([]zoekt.DocumentSectio continue } - symOffsets = append( - symOffsets[:i], - append([]zoekt.DocumentSection{{Start: start, End: endSym}}, symOffsets[i:]...)..., - ) - symMetaData = append( - symMetaData[:i], - append( - []*zoekt.Symbol{{Sym: t.Name, Kind: t.Kind, Parent: t.Parent, ParentKind: t.ParentKind}}, - symMetaData[i:]..., - )..., - ) + symOffsets = slices.Insert(symOffsets, i, zoekt.DocumentSection{ + Start: start, + End: endSym, + }) + symMetaData = slices.Insert(symMetaData, i, &zoekt.Symbol{ + Sym: t.Name, + Kind: t.Kind, + Parent: t.Parent, + ParentKind: t.ParentKind, + }) } return symOffsets, symMetaData, nil