Skip to content

Commit

Permalink
fix: SA6002
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed May 4, 2023
1 parent b3c440c commit a88edc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions bspool.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package gocloc

import "sync"
import (
"bytes"
"sync"
)

var bsPool = sync.Pool{New: func() interface{} { return make([]byte, 0, 128*1024) }}
var bsPool = sync.Pool{New: func() any { return new(bytes.Buffer) }}

func getByteSlice() []byte {
return bsPool.Get().([]byte)
func getByteSlice() *bytes.Buffer {
v := bsPool.Get().(*bytes.Buffer)
v.Reset()
return v
}

func putByteSlice(bs []byte) {
func putByteSlice(bs *bytes.Buffer) {
bsPool.Put(bs)
}
2 changes: 1 addition & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func AnalyzeReader(filename string, language *Language, file io.Reader, opts *Cl
buf := getByteSlice()
defer putByteSlice(buf)
scanner := bufio.NewScanner(file)
scanner.Buffer(buf, 1024*1024)
scanner.Buffer(buf.Bytes(), 1024*1024)

scannerloop:
for scanner.Scan() {
Expand Down

0 comments on commit a88edc5

Please sign in to comment.