From 8d538a1a52dee8b6d1401a27560d934a53696a01 Mon Sep 17 00:00:00 2001 From: Almer Lucke Date: Fri, 28 Nov 2025 12:50:21 +0100 Subject: [PATCH] Optimize store if allowOverwrite is true you don't have to do a possible expensive load first --- mightymap.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mightymap.go b/mightymap.go index dbd9ec5..39a2964 100644 --- a/mightymap.go +++ b/mightymap.go @@ -85,7 +85,9 @@ func (m *Map[K, V]) Has(ctx context.Context, key K) (ok bool) { // Store inserts or updates a value in the map for the given key. // If allowOverwrite is false, it will only insert if the key doesn't exist. func (m *Map[K, V]) Store(ctx context.Context, key K, value V) { - if _, ok := m.storage.Load(ctx, key); !ok || m.allowOverwrite { + if m.allowOverwrite { + m.storage.Store(ctx, key, value) + } else if _, ok := m.storage.Load(ctx, key); !ok { m.storage.Store(ctx, key, value) } }