core, ethdb: two tiny fixes (#17183)
* ethdb: fix memory database * core: fix bloombits checking * core: minor polish
This commit is contained in:
committed by
Péter Szilágyi
parent
323428865f
commit
dcdd57df62
@ -96,7 +96,10 @@ func (db *MemDatabase) NewBatch() Batch {
|
||||
|
||||
func (db *MemDatabase) Len() int { return len(db.db) }
|
||||
|
||||
type kv struct{ k, v []byte }
|
||||
type kv struct {
|
||||
k, v []byte
|
||||
del bool
|
||||
}
|
||||
|
||||
type memBatch struct {
|
||||
db *MemDatabase
|
||||
@ -105,13 +108,14 @@ type memBatch struct {
|
||||
}
|
||||
|
||||
func (b *memBatch) Put(key, value []byte) error {
|
||||
b.writes = append(b.writes, kv{common.CopyBytes(key), common.CopyBytes(value)})
|
||||
b.writes = append(b.writes, kv{common.CopyBytes(key), common.CopyBytes(value), false})
|
||||
b.size += len(value)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *memBatch) Delete(key []byte) error {
|
||||
b.writes = append(b.writes, kv{common.CopyBytes(key), nil})
|
||||
b.writes = append(b.writes, kv{common.CopyBytes(key), nil, true})
|
||||
b.size += 1
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -120,7 +124,7 @@ func (b *memBatch) Write() error {
|
||||
defer b.db.lock.Unlock()
|
||||
|
||||
for _, kv := range b.writes {
|
||||
if kv.v == nil {
|
||||
if kv.del {
|
||||
delete(b.db.db, string(kv.k))
|
||||
continue
|
||||
}
|
||||
|
Reference in New Issue
Block a user