Store sets the value for a key.
(key K, value V)
| 140 | |
| 141 | // Store sets the value for a key. |
| 142 | func (m *MapOf[K, V]) Store(key K, value V) { |
| 143 | read, _ := m.read.Load().(readOnly[K, V]) |
| 144 | if e, ok := read.m[key]; ok && e.tryStore(&value) { |
| 145 | return |
| 146 | } |
| 147 | |
| 148 | m.mu.Lock() |
| 149 | read, _ = m.read.Load().(readOnly[K, V]) |
| 150 | if e, ok := read.m[key]; ok { |
| 151 | if e.unexpungeLocked() { |
| 152 | // The entry was previously expunged, which implies that there is a |
| 153 | // non-nil dirty map and this entry is not in it. |
| 154 | m.dirty[key] = e |
| 155 | } |
| 156 | e.storeLocked(&value) |
| 157 | } else if e, ok := m.dirty[key]; ok { |
| 158 | e.storeLocked(&value) |
| 159 | } else { |
| 160 | if !read.amended { |
| 161 | // We're adding the first new key to the dirty map. |
| 162 | // Make sure it is allocated and mark the read-only map as incomplete. |
| 163 | m.dirtyLocked() |
| 164 | m.read.Store(readOnly[K, V]{m: read.m, amended: true}) |
| 165 | } |
| 166 | m.dirty[key] = newEntry(value) |
| 167 | } |
| 168 | m.mu.Unlock() |
| 169 | } |
| 170 | |
| 171 | // tryStore stores a value if the entry has not been expunged. |
| 172 | // |
no test coverage detected