@@ -21,29 +21,6 @@ type Issue struct {
21
21
DuplicatePos token.Position
22
22
}
23
23
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
-
47
24
// Config contains all configuration options for the goconst analyzer.
48
25
type Config struct {
49
26
// 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,
137
114
expectedIssues = 1000 // Cap at reasonable maximum
138
115
}
139
116
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 )
147
119
148
120
// Process files concurrently
149
121
var wg sync.WaitGroup
@@ -195,8 +167,8 @@ func RunWithConfig(files []*ast.File, fset *token.FileSet, typeInfo *types.Info,
195
167
p .stringMutex .RLock ()
196
168
p .stringCountMutex .RLock ()
197
169
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 ) )
200
172
201
173
// Create an array of strings to sort for stable output
202
174
for str := range p .strs {
@@ -243,8 +215,8 @@ func RunWithConfig(files []*ast.File, fset *token.FileSet, typeInfo *types.Info,
243
215
// process duplicate constants
244
216
p .constMutex .RLock ()
245
217
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 ))
248
220
249
221
// Create an array of strings and sort for stable output
250
222
for str := range p .consts {
@@ -271,9 +243,6 @@ func RunWithConfig(files []*ast.File, fset *token.FileSet, typeInfo *types.Info,
271
243
272
244
p .constMutex .RUnlock ()
273
245
274
- // Return string buffer to pool
275
- PutStringBuffer (stringKeys )
276
-
277
246
// Don't return the buffer to pool as the caller now owns it
278
247
return issueBuffer , nil
279
248
}
0 commit comments