]> Cypherpunks repositories - gostls13.git/commitdiff
os: remove dependency on strings package
authorIan Lance Taylor <iant@golang.org>
Thu, 17 Dec 2020 22:57:20 +0000 (14:57 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 18 Dec 2020 18:25:14 +0000 (18:25 +0000)
Historically the os package has not imported the strings package.
That was enforced by go/build.TestDependencies, but that test
was accidentally broken (#43249). A dependency of os on strings
was accidentally added by CL 266364; remove it.

For #42026
For #43249

Change-Id: If932308f30561fdcc5c608d7563e849c0d2870d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/279072
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
src/os/file_plan9.go
src/os/tempfile.go

index bbc732838a5f7c91b8247a2540da404acbfba633..4f384e9211061d526dd6c3ca736572e79389235d 100644 (file)
@@ -336,16 +336,6 @@ func hasPrefix(s, prefix string) bool {
        return len(s) >= len(prefix) && s[0:len(prefix)] == prefix
 }
 
-// LastIndexByte from the strings package.
-func lastIndex(s string, sep byte) int {
-       for i := len(s) - 1; i >= 0; i-- {
-               if s[i] == sep {
-                       return i
-               }
-       }
-       return -1
-}
-
 func rename(oldname, newname string) error {
        dirname := oldname[:lastIndex(oldname, '/')+1]
        if hasPrefix(newname, dirname) {
index 2728485c32ca158afbab291c111fd1ba12abe4cc..4f90fcf8e8512517852516350e927c436e87ca30 100644 (file)
@@ -4,10 +4,7 @@
 
 package os
 
-import (
-       "errors"
-       "strings"
-)
+import "errors"
 
 // fastrand provided by runtime.
 // We generate random temporary file names so that there's a good
@@ -62,7 +59,7 @@ func prefixAndSuffix(pattern string) (prefix, suffix string, err error) {
                        return "", "", errPatternHasSeparator
                }
        }
-       if pos := strings.LastIndex(pattern, "*"); pos != -1 {
+       if pos := lastIndex(pattern, '*'); pos != -1 {
                prefix, suffix = pattern[:pos], pattern[pos+1:]
        } else {
                prefix = pattern
@@ -116,3 +113,13 @@ func joinPath(dir, name string) string {
        }
        return dir + string(PathSeparator) + name
 }
+
+// LastIndexByte from the strings package.
+func lastIndex(s string, sep byte) int {
+       for i := len(s) - 1; i >= 0; i-- {
+               if s[i] == sep {
+                       return i
+               }
+       }
+       return -1
+}