bazel-skylib icon indicating copy to clipboard operation
bazel-skylib copied to clipboard

Question: redundant slice element in gazelle Import() function?

Open hchsiao opened this issue 3 years ago • 0 comments

While studying the source code, I came across this line: https://github.com/bazelbuild/bazel-skylib/blob/872e9b06e18ae8ba2897cb65b9aaa172aa6279f3/gazelle/bzl/gazelle.go#L114

Later on, imports will be appended by as many as len(srcs) elements: https://github.com/bazelbuild/bazel-skylib/blob/872e9b06e18ae8ba2897cb65b9aaa172aa6279f3/gazelle/bzl/gazelle.go#L116-L126

At the end, len(imports) and cap(imports) both become 2*len(srcs), which seems odd to me because at first it was only allocated for len(srcs) elements.

Does it make sense to change imports := make([]resolve.ImportSpec, len(srcs)) to imports := make([]resolve.ImportSpec, 0, len(srcs))?

Note that I am very new to golang, so chances are high that I could be wrong.

hchsiao avatar Aug 10 '22 14:08 hchsiao