I have this snippet of code that iterate over a map and filter some fields based on relation type, I have to run two loops and have a feeling that it is going to be slow for big maps. Is there any way I can technique/refactoring to make this code more performant.
func getFields(filter map[string]map[string]bool, msg *Message) (fs []Field) {
for k, _ := range filter {
if relationString(msg) == k {
if fieldFilter, ok := filter[k]; ok {
for _, f := range msg.Fields {
if _, ok := fieldFilter[f.Name]; ok {
fs = append(fs, f)
}
}
}
}
}
return
}