Skip to content

Commit

Permalink
compare bytes to avoid allocations
Browse files Browse the repository at this point in the history
we don't save the line, just the offset.
using the bytes versions avoids allocating new strings

Signed-off-by: Spencer Schrock <[email protected]>
  • Loading branch information
spencerschrock committed Mar 7, 2024
1 parent 6e360b8 commit 904ce51
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions checks/raw/sast.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,11 @@ func findLine(content, data []byte) (uint, error) {
r := bytes.NewReader(content)
scanner := bufio.NewScanner(r)

line := 0
// https://golang.org/pkg/bufio/#Scanner.Scan
var line uint
for scanner.Scan() {
line++
if strings.Contains(scanner.Text(), string(data)) {
return uint(line), nil
if bytes.Contains(scanner.Bytes(), data) {
return line, nil
}
}

Expand Down

0 comments on commit 904ce51

Please sign in to comment.