From: Kir Kolyshkin Date: Thu, 5 Sep 2024 01:38:05 +0000 (-0700) Subject: cmd/internal/script: use sync.OnceValue X-Git-Tag: go1.24rc1~961 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a77b93c0b2e2c50d1b0b9d181a4ee4eaf04f8821;p=gostls13.git cmd/internal/script: use sync.OnceValue Change-Id: I384a7391a26f24402c055aec98b37927305e2a39 Reviewed-on: https://go-review.googlesource.com/c/go/+/611042 Reviewed-by: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor --- diff --git a/src/cmd/internal/script/conds.go b/src/cmd/internal/script/conds.go index 25dd6e17ea..30759d2a58 100644 --- a/src/cmd/internal/script/conds.go +++ b/src/cmd/internal/script/conds.go @@ -123,13 +123,13 @@ func (b *boolCond) Eval(s *State, suffix string) (bool, error) { // The eval function is not passed a *State because the condition is cached // across all execution states and must not vary by state. func OnceCondition(summary string, eval func() (bool, error)) Cond { - return &onceCond{eval: eval, usage: CondUsage{Summary: summary}} + return &onceCond{ + eval: sync.OnceValues(eval), + usage: CondUsage{Summary: summary}, + } } type onceCond struct { - once sync.Once - v bool - err error eval func() (bool, error) usage CondUsage } @@ -140,8 +140,7 @@ func (l *onceCond) Eval(s *State, suffix string) (bool, error) { if suffix != "" { return false, ErrUsage } - l.once.Do(func() { l.v, l.err = l.eval() }) - return l.v, l.err + return l.eval() } // CachedCondition is like Condition but only calls eval the first time the