prealloc icon indicating copy to clipboard operation
prealloc copied to clipboard

prealloc is a Go static analysis tool to find slice declarations that could potentially be preallocated.

Results 10 prealloc issues
Sort by recently updated
recently updated
newest added

Preallocation of maps can be useful, as shown by PR #23, would be nice to have prealloc suggest that too. Just wondering how smart it can be made as things...

Results from system in front of me: ``` BenchmarkMap/Size10NoPreallocate-4 1954923 603.7 ns/op 484 B/op 3 allocs/op BenchmarkMap/Size10Preallocate-4 2951250 393.8 ns/op 340 B/op 2 allocs/op BenchmarkMap/Size200NoPreallocate-4 71530 15337 ns/op 11270 B/op...

When ranging over a list that contains conditional `break`/`continue` directives and a `slice = append(slice, element)` at the end, `prealloc` suggests preallocation. [No lint triggered](https://play.golang.org/p/ybpu7Q8FIJ7) ```go var a []int for...

I currently work in a team and we had a code issue a few times that made it beyond code review. It is pre-allocating a slice with size instead of...

feature-request

In the following function, ```prealloc``` is confused by ```buf``` being redeclared: ``` func copySort(w io.Writer, r io.Reader, sep rune, keys []int) error { // Copy the header line. var buf...

When the initial value is a pre-allocated slice, it should not be considered as a candidate for suggestion. So we try to recognize the `make` function and skip when the...

If a pre-allocated slice is declared by `var` statement and explicit type, it would be incorrectly reported as a candidate for pre-allocation. For instance, the code snippet following would be...

Example setup to reproduce the issue. **foo.txt** ```text some dummy text /* some comment */ more dummy text // some comment even more dummy text ``` **main.go** ```go type FooLine...

Even with `simple=true`, the linter reports about preallocating slices. Here is one such example: ```go var ents []*Entity //

bug
help wanted

The `prealloc` code seems to assume that the length of whatever you are iterating over is known in advance. But this is no longer true with the new Go 1.23...

bug
help wanted