]> Cypherpunks repositories - gostls13.git/commitdiff
internal/testenv: use sync.OnceValues for hasSymlink
authorKir Kolyshkin <kolyshkin@gmail.com>
Fri, 30 Aug 2024 07:23:50 +0000 (00:23 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 3 Sep 2024 19:31:55 +0000 (19:31 +0000)
On some platforms (android, wasip1) this function is called many
times which probably results in some slowdown, especially for wasip1.

Wrap it into sync.OnceValues.

Change-Id: Id290ffd8d1e7ad806302f457e8fff2e3123b49a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/609418
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/internal/testenv/testenv_notwin.go

index 30e159a6ecd4a2d2902639e33378f3a603d36352..9dddea94d05798982aaf14e9e8dc2c63bb70dacf 100644 (file)
@@ -11,9 +11,10 @@ import (
        "os"
        "path/filepath"
        "runtime"
+       "sync"
 )
 
-func hasSymlink() (ok bool, reason string) {
+var hasSymlink = sync.OnceValues(func() (ok bool, reason string) {
        switch runtime.GOOS {
        case "plan9":
                return false, ""
@@ -43,4 +44,4 @@ func hasSymlink() (ok bool, reason string) {
        }
 
        return true, ""
-}
+})