@@ -14,7 +14,7 @@ type BatchWithFlusher struct {
1414 flushThreshold int // The threshold to flush the batch to disk.
1515}
1616
17- var _ dbm.Batch = & BatchWithFlusher {}
17+ var _ dbm.Batch = ( * BatchWithFlusher )( nil )
1818
1919// NewBatchWithFlusher returns new BatchWithFlusher wrapping the passed in batch
2020func NewBatchWithFlusher (db dbm.DB , flushThreshold int ) * BatchWithFlusher {
@@ -45,27 +45,21 @@ func (b *BatchWithFlusher) estimateSizeAfterSetting(key []byte, value []byte) (i
4545// If the set causes the underlying batch size to exceed flushThreshold,
4646// the batch is flushed to disk, cleared, and a new one is created with buffer pre-allocated to threshold.
4747// The addition entry is then added to the batch.
48- func (b * BatchWithFlusher ) Set (key [] byte , value []byte ) error {
48+ func (b * BatchWithFlusher ) Set (key , value []byte ) error {
4949 batchSizeAfter , err := b .estimateSizeAfterSetting (key , value )
5050 if err != nil {
5151 return err
5252 }
5353 if batchSizeAfter > b .flushThreshold {
54- err = b .batch .Write ()
55- if err != nil {
54+ if err := b .batch .Write (); err != nil {
5655 return err
5756 }
58- err = b .batch .Close ()
59- if err != nil {
57+ if err := b .batch .Close (); err != nil {
6058 return err
6159 }
6260 b .batch = b .db .NewBatchWithSize (b .flushThreshold )
6361 }
64- err = b .batch .Set (key , value )
65- if err != nil {
66- return err
67- }
68- return nil
62+ return b .batch .Set (key , value )
6963}
7064
7165// Delete delete value at the given key to the db.
@@ -78,21 +72,15 @@ func (b *BatchWithFlusher) Delete(key []byte) error {
7872 return err
7973 }
8074 if batchSizeAfter > b .flushThreshold {
81- err = b .batch .Write ()
82- if err != nil {
75+ if err := b .batch .Write (); err != nil {
8376 return err
8477 }
85- err = b .batch .Close ()
86- if err != nil {
78+ if err := b .batch .Close (); err != nil {
8779 return err
8880 }
8981 b .batch = b .db .NewBatchWithSize (b .flushThreshold )
9082 }
91- err = b .batch .Delete (key )
92- if err != nil {
93- return err
94- }
95- return nil
83+ return b .batch .Delete (key )
9684}
9785
9886func (b * BatchWithFlusher ) Write () error {
0 commit comments