From 36cd880878a9804489557c29fa768647d665fbe0 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 19 Mar 2024 19:27:22 -0700 Subject: [PATCH] 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 --- src/sync/map.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 { -- 2.50.0