From: Peter Collingbourne Date: Wed, 20 Mar 2024 02:27:22 +0000 (-0700) Subject: sync: name the Map.CompareAndSwap return value X-Git-Tag: go1.23rc1~817 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=36cd880878a9804489557c29fa768647d665fbe0;p=gostls13.git sync: name the Map.CompareAndSwap return value The godoc for sync.Map.CompareAndSwap does not document the meaning of its return value. Document it by giving it a name. Change-Id: I50ad9c078a7885f5ce83489d66d138d491c35861 Reviewed-on: https://go-review.googlesource.com/c/go/+/572657 Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- diff --git a/src/sync/map.go b/src/sync/map.go index 7ae97bce1d..504410bc4b 100644 --- a/src/sync/map.go +++ b/src/sync/map.go @@ -393,7 +393,7 @@ func (m *Map) Swap(key, value any) (previous any, loaded bool) { // CompareAndSwap swaps the old and new values for key // if the value stored in the map is equal to old. // The old value must be of a comparable type. -func (m *Map) CompareAndSwap(key, old, new any) bool { +func (m *Map) CompareAndSwap(key, old, new any) (swapped bool) { read := m.loadReadOnly() if e, ok := read.m[key]; ok { return e.tryCompareAndSwap(old, new) @@ -404,7 +404,7 @@ func (m *Map) CompareAndSwap(key, old, new any) bool { m.mu.Lock() defer m.mu.Unlock() read = m.loadReadOnly() - swapped := false + swapped = false if e, ok := read.m[key]; ok { swapped = e.tryCompareAndSwap(old, new) } else if e, ok := m.dirty[key]; ok {