From 1b6e683180bde14d013a7d992dea06e67b30413d Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Mon, 30 Jan 2023 05:48:57 -0500 Subject: [PATCH] impr(cachekv): Move check outside lock. (#14831) --- store/cachekv/store.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 4cd890d330..85fb6353c0 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -69,12 +69,11 @@ func (store *Store) Get(key []byte) (value []byte) { // Set implements types.KVStore. func (store *Store) Set(key []byte, value []byte) { - store.mtx.Lock() - defer store.mtx.Unlock() - types.AssertValidKey(key) types.AssertValidValue(value) + store.mtx.Lock() + defer store.mtx.Unlock() store.setCacheValue(key, value, true) } @@ -86,10 +85,11 @@ func (store *Store) Has(key []byte) bool { // Delete implements types.KVStore. func (store *Store) Delete(key []byte) { + types.AssertValidKey(key) + store.mtx.Lock() defer store.mtx.Unlock() - types.AssertValidKey(key) store.setCacheValue(key, nil, true) }