mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
keydir: avoid defers (#34)
This commit is contained in:
parent
e3242c8426
commit
8aa66c66da
@ -42,17 +42,15 @@ func (k *Keydir) Add(key string, fileid int, offset, size int64) Item {
|
|||||||
|
|
||||||
func (k *Keydir) Get(key string) (Item, bool) {
|
func (k *Keydir) Get(key string) (Item, bool) {
|
||||||
k.RLock()
|
k.RLock()
|
||||||
defer k.RUnlock()
|
|
||||||
|
|
||||||
item, ok := k.kv[key]
|
item, ok := k.kv[key]
|
||||||
|
k.RUnlock()
|
||||||
return item, ok
|
return item, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *Keydir) Delete(key string) {
|
func (k *Keydir) Delete(key string) {
|
||||||
k.Lock()
|
k.Lock()
|
||||||
defer k.Unlock()
|
|
||||||
|
|
||||||
delete(k.kv, key)
|
delete(k.kv, key)
|
||||||
|
k.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *Keydir) Len() int {
|
func (k *Keydir) Len() int {
|
||||||
@ -63,11 +61,11 @@ func (k *Keydir) Keys() chan string {
|
|||||||
ch := make(chan string)
|
ch := make(chan string)
|
||||||
go func() {
|
go func() {
|
||||||
k.RLock()
|
k.RLock()
|
||||||
defer k.RUnlock()
|
|
||||||
for key := range k.kv {
|
for key := range k.kv {
|
||||||
ch <- key
|
ch <- key
|
||||||
}
|
}
|
||||||
close(ch)
|
close(ch)
|
||||||
|
k.RUnlock()
|
||||||
}()
|
}()
|
||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user