Skip to content

Commit

Permalink
re-use ancestors count information across calls
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Nov 9, 2024
1 parent d65bb66 commit 99e3d8f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/security/secl/compiler/eval/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Context struct {
Registers map[RegisterID]int

now time.Time

CachedAncestorsCount int
}

// Now return and cache the `now` timestamp
Expand Down
8 changes: 2 additions & 6 deletions pkg/security/secl/model/string_array_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ package model
import "github.com/DataDog/datadog-agent/pkg/security/secl/compiler/eval"

func newAncestorsIterator[T any](iter *ProcessAncestorsIterator, ctx *eval.Context, ev *Event, perIter func(ev *Event, pce *ProcessCacheEntry) T) []T {
var count int
for pce := iter.Front(ctx); pce != nil; pce = iter.Next() {
count++
}

results := make([]T, 0, count)
results := make([]T, 0, ctx.CachedAncestorsCount)
for pce := iter.Front(ctx); pce != nil; pce = iter.Next() {
results = append(results, perIter(ev, pce))
}
ctx.CachedAncestorsCount = len(results)

return results
}

0 comments on commit 99e3d8f

Please sign in to comment.