diff --git a/pkg/config/generic_map.go b/pkg/config/generic_map.go index e8c899020..91cb17ddc 100644 --- a/pkg/config/generic_map.go +++ b/pkg/config/generic_map.go @@ -21,7 +21,7 @@ type GenericMap map[string]interface{} // Copy will create a flat copy of GenericMap func (m GenericMap) Copy() GenericMap { - result := GenericMap{} + result := make(GenericMap, len(m)) for k, v := range m { result[k] = v diff --git a/pkg/config/generic_map_test.go b/pkg/config/generic_map_test.go new file mode 100644 index 000000000..b68d37366 --- /dev/null +++ b/pkg/config/generic_map_test.go @@ -0,0 +1,17 @@ +package config + +import ( + "fmt" + "testing" +) + +func BenchmarkGenericMap_Copy(b *testing.B) { + m := GenericMap{} + for i := 0; i < 20; i++ { + m[fmt.Sprintf("key-%d", i)] = fmt.Sprintf("value-%d", i) + } + + for i := 0; i < b.N; i++ { + _ = m.Copy() + } +}