Skip to content

Commit 2de7866

Browse files
os: remove dependency on strings package
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Tobias Klauser <[email protected]>
1 parent ae652a4 commit 2de7866

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/os/file_plan9.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,6 @@ func hasPrefix(s, prefix string) bool {
336336
return len(s) >= len(prefix) && s[0:len(prefix)] == prefix
337337
}
338338

339-
// LastIndexByte from the strings package.
340-
func lastIndex(s string, sep byte) int {
341-
for i := len(s) - 1; i >= 0; i-- {
342-
if s[i] == sep {
343-
return i
344-
}
345-
}
346-
return -1
347-
}
348-
349339
func rename(oldname, newname string) error {
350340
dirname := oldname[:lastIndex(oldname, '/')+1]
351341
if hasPrefix(newname, dirname) {

src/os/tempfile.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
package os
66

7-
import (
8-
"errors"
9-
"strings"
10-
)
7+
import "errors"
118

129
// fastrand provided by runtime.
1310
// 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) {
6259
return "", "", errPatternHasSeparator
6360
}
6461
}
65-
if pos := strings.LastIndex(pattern, "*"); pos != -1 {
62+
if pos := lastIndex(pattern, '*'); pos != -1 {
6663
prefix, suffix = pattern[:pos], pattern[pos+1:]
6764
} else {
6865
prefix = pattern
@@ -116,3 +113,13 @@ func joinPath(dir, name string) string {
116113
}
117114
return dir + string(PathSeparator) + name
118115
}
116+
117+
// LastIndexByte from the strings package.
118+
func lastIndex(s string, sep byte) int {
119+
for i := len(s) - 1; i >= 0; i-- {
120+
if s[i] == sep {
121+
return i
122+
}
123+
}
124+
return -1
125+
}

0 commit comments

Comments
 (0)