Skip to content

Commit

Permalink
Merge pull request #26 from mandiant/optimize/willi-1
Browse files Browse the repository at this point in the history
objfile: optimize findAllOccurrences
  • Loading branch information
stevemk14ebr authored Aug 2, 2023
2 parents f2009bd + 473fdfb commit ad76d74
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions objfile/objfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,23 @@ func (x byAddr) Swap(i, j int) { x[i], x[j] = x[j], x[i] }

func findAllOccurrences(data []byte, searches [][]byte) []int {
var results []int

for _, search := range searches {
for idx := range data {
if len(data[idx:]) < len(search) {
continue
}
var offset = 0

haystack := data[idx : idx+len(search)]
if bytes.Equal(haystack, search) {
results = append(results, idx)
for {
var index = bytes.Index(data[offset:], search)
if index == -1 {
break
}

offset += index
results = append(results, offset)

offset += 1
}
}

return results
}

Expand Down

0 comments on commit ad76d74

Please sign in to comment.