Skip to content

Commit 5a393b5

Browse files
committed
Add missing EnsureCapacity call
1 parent b3cebce commit 5a393b5

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

pkg/ottl/expression.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ func newMapGetter[K any](mapValues map[string]Getter[K]) (Getter[K], error) {
208208

209209
func (m *mapGetter[K]) Get(ctx context.Context, tCtx K) (any, error) {
210210
result := pcommon.NewMap()
211+
result.EnsureCapacity(len(m.mapValues))
211212
for k, v := range m.mapValues {
212213
val, err := v.Get(ctx, tCtx)
213214
if err != nil {
@@ -219,6 +220,7 @@ func (m *mapGetter[K]) Get(ctx context.Context, tCtx K) (any, error) {
219220
typedVal.CopyTo(target)
220221
case []any:
221222
target := result.PutEmpty(k).SetEmptySlice()
223+
target.EnsureCapacity(len(typedVal))
222224
for _, el := range typedVal {
223225
switch typedEl := el.(type) {
224226
case pcommon.Map:

pkg/ottl/ottlfuncs/func_extract_grok_patterns.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func extractGrokPatterns[K any](target, pattern ottl.StringGetter[K], nco ottl.O
107107
}
108108

109109
result := pcommon.NewMap()
110+
result.EnsureCapacity(len(matches))
110111
for k, v := range matches {
111112
switch val := v.(type) {
112113
case bool:

0 commit comments

Comments
 (0)