1
0
mirror of https://github.com/golang/go synced 2024-09-28 17:24:28 -06:00

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 <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Peter Collingbourne 2024-03-19 19:27:22 -07:00 committed by Gopher Robot
parent 7d4d71e52f
commit 36cd880878

View File

@ -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 {