]> Cypherpunks repositories - gostls13.git/commitdiff
all: remove strings.Contains check around Replace
authorDaniel Martí <mvdan@mvdan.cc>
Mon, 11 Sep 2017 19:51:38 +0000 (21:51 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 12 Sep 2017 08:58:28 +0000 (08:58 +0000)
It doesn't change the outcome. It might have been useful at some point
to avoid Replace from doing work or allocating. However, nowadays the
func returns early without doing any work if Count returns 0.

Change-Id: Id69dc74042a6e39672b405016484db8b50f43d58
Reviewed-on: https://go-review.googlesource.com/62991
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
src/path/filepath/path_windows.go
src/text/template/exec.go

index 0d8b62015c56846883da962fe319df7b33635fa9..03542559f8b3ca9c5268c97c9c2f722e9c5f51cc 100644 (file)
@@ -100,9 +100,7 @@ func splitList(path string) []string {
 
        // Remove quotes.
        for i, s := range list {
-               if strings.Contains(s, `"`) {
-                       list[i] = strings.Replace(s, `"`, ``, -1)
-               }
+               list[i] = strings.Replace(s, `"`, ``, -1)
        }
 
        return list
index e54a579afd19253dba394895f77d6c798d0fa239..1c361ed13e067de90124c639eb8e471ff13a3b23 100644 (file)
@@ -79,10 +79,7 @@ func (s *state) at(node parse.Node) {
 // doublePercent returns the string with %'s replaced by %%, if necessary,
 // so it can be used safely inside a Printf format string.
 func doublePercent(str string) string {
-       if strings.Contains(str, "%") {
-               str = strings.Replace(str, "%", "%%", -1)
-       }
-       return str
+       return strings.Replace(str, "%", "%%", -1)
 }
 
 // TODO: It would be nice if ExecError was more broken down, but