@@ -34,13 +34,16 @@ type Store struct {
3434 traceContext types.TraceContext
3535}
3636
37+ // PooledStore is a wrapper around Store that implements the PooledCacheKVStore interface.
38+ // It's used to avoid allocating new Store instances .
3739type PooledStore struct {
3840 Store
3941}
4042
41- var _ types.CacheMultiStore = & Store {}
42-
43- var _ types.PooledCacheMultiStore = & PooledStore {}
43+ var (
44+ _ types.CacheMultiStore = & Store {}
45+ _ types.PooledCacheMultiStore = & PooledStore {}
46+ )
4447
4548// NewFromKVStore creates a new Store object from a mapping of store keys to
4649// CacheWrapper objects and a KVStore as the database. Each CacheWrapper store
@@ -91,6 +94,8 @@ var storePool = sync.Pool{
9194 },
9295}
9396
97+ // newFromKVStorePooled returns a PooledStore object, populated with a mapping of store keys to
98+ // CacheWrapper objects and a KVStore as the database.
9499func newFromKVStorePooled (
95100 store types.KVStore , stores map [types.StoreKey ]types.CacheWrap ,
96101 traceWriter io.Writer , traceContext types.TraceContext ,
@@ -113,6 +118,7 @@ func newFromKVStorePooled(
113118 return cms
114119}
115120
121+ // Release releases the PooledStore object back to the pool.
116122func (cms * PooledStore ) Release () {
117123 // clear the stores map
118124 for k , v := range cms .stores {
@@ -202,6 +208,7 @@ func (cms *Store) CacheMultiStore() types.CacheMultiStore {
202208 return newCacheMultiStoreFromCMS (cms )
203209}
204210
211+ // CacheMultiStorePooled returns a PooledCacheMultiStore object from a pool.
205212func (cms * Store ) CacheMultiStorePooled () types.PooledCacheMultiStore {
206213 return newFromKVStorePooled (cms .db , cms .stores , cms .traceWriter , cms .traceContext )
207214}
0 commit comments