From 904ce517e2e1d9ad819a8e99eb6268d72dccc0c1 Mon Sep 17 00:00:00 2001 From: Spencer Schrock Date: Thu, 7 Mar 2024 10:27:13 -0800 Subject: [PATCH] compare bytes to avoid allocations we don't save the line, just the offset. using the bytes versions avoids allocating new strings Signed-off-by: Spencer Schrock --- checks/raw/sast.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/checks/raw/sast.go b/checks/raw/sast.go index 55fa1d316fd..54ce809906c 100644 --- a/checks/raw/sast.go +++ b/checks/raw/sast.go @@ -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 } }