From 82a41e17c742cf9b7ea9d362710433f49246bab6 Mon Sep 17 00:00:00 2001 From: SmallCoccinelle <89733524+SmallCoccinelle@users.noreply.github.com> Date: Thu, 9 Sep 2021 06:10:39 +0200 Subject: [PATCH] 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. --- pkg/scraper/mapped.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/scraper/mapped.go b/pkg/scraper/mapped.go index 8a8e2b847..ca5c7b1b8 100644 --- a/pkg/scraper/mapped.go +++ b/pkg/scraper/mapped.go @@ -32,9 +32,7 @@ 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) - } + ret = strings.Replace(ret, commonKey, commonVal, -1) } return ret