tryLoadOrStore atomically loads or stores a value if the entry is not expunged. If the entry is expunged, tryLoadOrStore leaves the entry unchanged and returns with ok==false.
(i V)
| 249 | // If the entry is expunged, tryLoadOrStore leaves the entry unchanged and |
| 250 | // returns with ok==false. |
| 251 | func (e *entry[V]) tryLoadOrStore(i V) (actual V, loaded, ok bool) { |
| 252 | p := e.p.Load() |
| 253 | if p == expungedFor[V]() { |
| 254 | return actual, false, false |
| 255 | } |
| 256 | if p != nil { |
| 257 | return *(*V)(p), true, true |
| 258 | } |
| 259 | |
| 260 | // Copy the value after the first load to make this method more amenable |
| 261 | // to escape analysis: if we hit the "load" path or the entry is expunged, we |
| 262 | // shouldn't bother heap-allocating. |
| 263 | ic := i |
| 264 | for { |
| 265 | if e.p.CompareAndSwap(nil, &ic) { |
| 266 | return i, false, true |
| 267 | } |
| 268 | p = e.p.Load() |
| 269 | if p == expungedFor[V]() { |
| 270 | return actual, false, false |
| 271 | } |
| 272 | if p != nil { |
| 273 | return *(*V)(p), true, true |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // Delete deletes the value for a key. |
| 279 | func (m *MapOf[K, V]) Delete(key K) { |