Avoid wrapping strings.Replace in Contains (#1710)

The strings.Replace function counts the number of replacements. If 0,
the original string is returned. Hence, there is no need to check if a
replacement will happen before doing the work.
This commit is contained in:
SmallCoccinelle
2021-09-09 06:10:39 +02:00
committed by GitHub
parent 4b00d24248
commit 82a41e17c7

View File

@@ -32,10 +32,8 @@ func (s mappedConfig) applyCommon(c commonMappedConfig, src string) string {
ret := src
for commonKey, commonVal := range c {
if strings.Contains(ret, commonKey) {
ret = strings.Replace(ret, commonKey, commonVal, -1)
}
}
return ret
}