@@ -21,29 +21,6 @@ type Issue struct {
2121 DuplicatePos token.Position
2222}
2323
24- // IssuePool provides a pool of Issue slices to reduce allocations
25- var IssuePool = sync.Pool {
26- New : func () interface {} {
27- return make ([]Issue , 0 , 100 )
28- },
29- }
30-
31- // GetIssueBuffer retrieves an Issue slice from the pool
32- func GetIssueBuffer () []Issue {
33- return IssuePool .Get ().([]Issue )[:0 ] // Reset length but keep capacity
34- }
35-
36- // PutIssueBuffer returns an Issue slice to the pool
37- func PutIssueBuffer (issues []Issue ) {
38- // Make sure to clear references before returning to pool
39- for i := range issues {
40- issues [i ].MatchingConst = ""
41- issues [i ].Str = ""
42- }
43- // Return the slice to the pool
44- IssuePool .Put (make ([]Issue , 0 , cap (issues ))) //nolint:staticcheck
45- }
46-
4724// Config contains all configuration options for the goconst analyzer.
4825type Config struct {
4926 // IgnoreStrings is a list of regular expressions to filter strings
@@ -137,13 +114,8 @@ func RunWithConfig(files []*ast.File, fset *token.FileSet, typeInfo *types.Info,
137114 expectedIssues = 1000 // Cap at reasonable maximum
138115 }
139116
140- // Get issue buffer from pool instead of allocating
141- issueBuffer := GetIssueBuffer ()
142- if cap (issueBuffer ) < expectedIssues {
143- // Only allocate new buffer if existing one is too small
144- PutIssueBuffer (issueBuffer )
145- issueBuffer = make ([]Issue , 0 , expectedIssues )
146- }
117+ // Allocate a new buffer
118+ issueBuffer := make ([]Issue , 0 , expectedIssues )
147119
148120 // Process files concurrently
149121 var wg sync.WaitGroup
@@ -195,8 +167,8 @@ func RunWithConfig(files []*ast.File, fset *token.FileSet, typeInfo *types.Info,
195167 p .stringMutex .RLock ()
196168 p .stringCountMutex .RLock ()
197169
198- // Get a string buffer from pool instead of allocating
199- stringKeys := GetStringBuffer ( )
170+ // Create a slice to hold the string keys
171+ stringKeys := make ([] string , 0 , len ( p . strs ) )
200172
201173 // Create an array of strings to sort for stable output
202174 for str := range p .strs {
@@ -243,8 +215,8 @@ func RunWithConfig(files []*ast.File, fset *token.FileSet, typeInfo *types.Info,
243215 // process duplicate constants
244216 p .constMutex .RLock ()
245217
246- // reuse string buffer for const keys
247- stringKeys = stringKeys [: 0 ]
218+ // Create a new slice for const keys
219+ stringKeys = make ([] string , 0 , len ( p . consts ))
248220
249221 // Create an array of strings and sort for stable output
250222 for str := range p .consts {
@@ -271,9 +243,6 @@ func RunWithConfig(files []*ast.File, fset *token.FileSet, typeInfo *types.Info,
271243
272244 p .constMutex .RUnlock ()
273245
274- // Return string buffer to pool
275- PutStringBuffer (stringKeys )
276-
277246 // Don't return the buffer to pool as the caller now owns it
278247 return issueBuffer , nil
279248}
0 commit comments