From 8c79a911331e7b504ae3c6a4e03edc6629728ce3 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 9 May 2023 15:29:03 -0700 Subject: [PATCH] mount-utils: isMountPointMatch: simplify and speedup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Here's before/after comparison. [kir@kir-rhat mount-utils]$ benchstat before after name old time/op new time/op delta IsMountPointMatch-4 707ns ± 1% 40ns ± 1% -94.39% (p=0.008 n=5+5) name old alloc/op new alloc/op delta IsMountPointMatch-4 264B ± 0% 0B -100.00% (p=0.008 n=5+5) name old allocs/op new allocs/op delta IsMountPointMatch-4 11.0 ± 0% 0.0 -100.00% (p=0.008 n=5+5) Signed-off-by: Kir Kolyshkin --- staging/src/k8s.io/mount-utils/mount_helper_unix.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/staging/src/k8s.io/mount-utils/mount_helper_unix.go b/staging/src/k8s.io/mount-utils/mount_helper_unix.go index cb8732fce74..7b1eb6af1b7 100644 --- a/staging/src/k8s.io/mount-utils/mount_helper_unix.go +++ b/staging/src/k8s.io/mount-utils/mount_helper_unix.go @@ -173,8 +173,7 @@ func splitMountOptions(s string) []string { // isMountPointMatch returns true if the path in mp is the same as dir. // Handles case where mountpoint dir has been renamed due to stale NFS mount. func isMountPointMatch(mp MountPoint, dir string) bool { - deletedDir := fmt.Sprintf("%s\\040(deleted)", dir) - return ((mp.Path == dir) || (mp.Path == deletedDir)) + return strings.TrimSuffix(mp.Path, "\\040(deleted)") == dir } // PathExists returns true if the specified path exists.