Skip to content

Commit

Permalink
build: use slices.Insert instead of several appends
Browse files Browse the repository at this point in the history
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
  • Loading branch information
keegancsmith committed Nov 6, 2023
1 parent 0ff0dd5 commit b4f3d1c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions build/ctags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"sync"
"time"

"golang.org/x/exp/slices"

"github.com/sourcegraph/zoekt"
"github.com/sourcegraph/zoekt/ctags"
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b4f3d1c

Please sign in to comment.