Skip to content

Commit 65d4270

Browse files
Merge pull request #4 from thisisdevelopment/optimize_store_allow_overwrite
Optimize store if allowOverwrite is true you don't have to do a possi…
2 parents c5debfb + 8d538a1 commit 65d4270

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

mightymap.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ func (m *Map[K, V]) Has(ctx context.Context, key K) (ok bool) {
8585
// Store inserts or updates a value in the map for the given key.
8686
// If allowOverwrite is false, it will only insert if the key doesn't exist.
8787
func (m *Map[K, V]) Store(ctx context.Context, key K, value V) {
88-
if _, ok := m.storage.Load(ctx, key); !ok || m.allowOverwrite {
88+
if m.allowOverwrite {
89+
m.storage.Store(ctx, key, value)
90+
} else if _, ok := m.storage.Load(ctx, key); !ok {
8991
m.storage.Store(ctx, key, value)
9092
}
9193
}

0 commit comments

Comments
 (0)