dao: simplify NewPrivate

This commit is contained in:
Roman Khimov 2022-02-18 14:18:56 +03:00
parent 5402e654d1
commit e864768c88

View file

@ -68,17 +68,13 @@ func (dao *Simple) GetWrapped() *Simple {
// GetPrivate returns new DAO instance with another layer of private // GetPrivate returns new DAO instance with another layer of private
// MemCachedStore around the current DAO Store. // MemCachedStore around the current DAO Store.
func (dao *Simple) GetPrivate() *Simple { func (dao *Simple) GetPrivate() *Simple {
st := storage.NewPrivateMemCachedStore(dao.Store) d := &Simple{}
d := newSimple(st, dao.Version.StateRootInHeader, dao.Version.P2PSigExtensions) *d = *dao // Inherit everything...
d.Version = dao.Version d.Store = storage.NewPrivateMemCachedStore(dao.Store) // except storage, wrap another layer.
if dao.keyBuf != nil { // This one is private. if d.keyBuf == nil {
d.keyBuf = dao.keyBuf // Thus we can reuse its buffer.
} else {
d.keyBuf = make([]byte, 0, 1+4+storage.MaxStorageKeyLen) // Prefix, uint32, key. d.keyBuf = make([]byte, 0, 1+4+storage.MaxStorageKeyLen) // Prefix, uint32, key.
} }
if dao.dataBuf != nil { // This one is private. if dao.dataBuf == nil {
d.dataBuf = dao.dataBuf // Thus we can reuse its buffer.
} else {
d.dataBuf = io.NewBufBinWriter() d.dataBuf = io.NewBufBinWriter()
} }
return d return d