]> Cypherpunks repositories - gostls13.git/commitdiff
os: use sync.OnceValue
authorapocelipes <seve3r@outlook.com>
Mon, 21 Oct 2024 15:28:25 +0000 (15:28 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 23 Oct 2024 15:16:26 +0000 (15:16 +0000)
Simplify the code and reduce global variables.

Change-Id: Id322836e8b6b6c4434136b95700ed4070ba52300
GitHub-Last-Rev: 7c9d409855c682b6de1f338f69d9193a7887f9f0
GitHub-Pull-Request: golang/go#69962
Reviewed-on: https://go-review.googlesource.com/c/go/+/621456
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
src/os/file_windows.go

index f8a6c09bb5c45c3a66135a1aba4ccd60352fbadd..465cf5d1862beada941c3d295f8e50d2e0658987 100644 (file)
@@ -223,17 +223,13 @@ func Pipe() (r *File, w *File, err error) {
        return newFile(p[0], "|0", "pipe"), newFile(p[1], "|1", "pipe"), nil
 }
 
-var (
-       useGetTempPath2Once sync.Once
-       useGetTempPath2     bool
-)
+var useGetTempPath2 = sync.OnceValue(func() bool {
+       return windows.ErrorLoadingGetTempPath2() == nil
+})
 
 func tempDir() string {
-       useGetTempPath2Once.Do(func() {
-               useGetTempPath2 = (windows.ErrorLoadingGetTempPath2() == nil)
-       })
        getTempPath := syscall.GetTempPath
-       if useGetTempPath2 {
+       if useGetTempPath2() {
                getTempPath = windows.GetTempPath2
        }
        n := uint32(syscall.MAX_PATH)