1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-08-10 22:31:50 +02:00

attribute: preallocate map in NewAllowKeysFilter and NewDenyKeysFilter (#6455)

preallocate map in `NewAllowKeysFilter` and `NewDenyKeysFilter` to avoid
necessary allocations
This commit is contained in:
ian
2025-03-18 23:38:17 +08:00
committed by GitHub
parent e15c058035
commit 8dc08e26b4
2 changed files with 3 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ func NewAllowKeysFilter(keys ...Key) Filter {
return func(kv KeyValue) bool { return false }
}
allowed := make(map[Key]struct{})
allowed := make(map[Key]struct{}, len(keys))
for _, k := range keys {
allowed[k] = struct{}{}
}
@@ -38,7 +38,7 @@ func NewDenyKeysFilter(keys ...Key) Filter {
return func(kv KeyValue) bool { return true }
}
forbid := make(map[Key]struct{})
forbid := make(map[Key]struct{}, len(keys))
for _, k := range keys {
forbid[k] = struct{}{}
}