From 476a352522a403537e8d295bced21a0a5df32591 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 29 Apr 2024 15:35:54 +0200 Subject: [PATCH] syscall: use stringslite.Has{Prefix,Suffix} Change-Id: I393191b95eeb8e17345ce28cfa1fb54a3ef13951 Reviewed-on: https://go-review.googlesource.com/c/go/+/582237 Auto-Submit: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Damien Neil LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot --- src/syscall/fs_wasip1.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/syscall/fs_wasip1.go b/src/syscall/fs_wasip1.go index 4d3d7d72c6..f19e8f3b3c 100644 --- a/src/syscall/fs_wasip1.go +++ b/src/syscall/fs_wasip1.go @@ -7,6 +7,7 @@ package syscall import ( + "internal/stringslite" "runtime" "unsafe" ) @@ -468,19 +469,11 @@ func joinPath(dir, file string) string { } func isAbs(path string) bool { - return hasPrefix(path, "/") + return stringslite.HasPrefix(path, "/") } func isDir(path string) bool { - return hasSuffix(path, "/") -} - -func hasPrefix(s, p string) bool { - return len(s) >= len(p) && s[:len(p)] == p -} - -func hasSuffix(s, x string) bool { - return len(s) >= len(x) && s[len(s)-len(x):] == x + return stringslite.HasSuffix(path, "/") } // preparePath returns the preopen file descriptor of the directory to perform @@ -500,7 +493,7 @@ func preparePath(path string) (int32, unsafe.Pointer, size) { path = joinPath(dir, path) for _, p := range preopens { - if len(p.name) > len(dirName) && hasPrefix(path, p.name) { + if len(p.name) > len(dirName) && stringslite.HasPrefix(path, p.name) { dirFd, dirName = p.fd, p.name } }