core/state: optimize GetState

There is no need to use the reflection-based decoder to decode []byte.
This commit is contained in:
Felix Lange 2016-10-05 22:56:07 +02:00
parent 90fce8bfa6
commit 3c836dd71b

View File

@ -153,10 +153,13 @@ func (self *StateObject) GetState(db trie.Database, key common.Hash) common.Hash
return value return value
} }
// Load from DB in case it is missing. // Load from DB in case it is missing.
tr := self.getTrie(db) if enc := self.getTrie(db).Get(key[:]); len(enc) > 0 {
var ret []byte _, content, _, err := rlp.Split(enc)
rlp.DecodeBytes(tr.Get(key[:]), &ret) if err != nil {
value = common.BytesToHash(ret) self.setError(err)
}
value.SetBytes(content)
}
if (value != common.Hash{}) { if (value != common.Hash{}) {
self.cachedStorage[key] = value self.cachedStorage[key] = value
} }
@ -209,7 +212,6 @@ func (self *StateObject) updateRoot(db trie.Database) {
func (self *StateObject) CommitTrie(db trie.Database, dbw trie.DatabaseWriter) error { func (self *StateObject) CommitTrie(db trie.Database, dbw trie.DatabaseWriter) error {
self.updateTrie(db) self.updateTrie(db)
if self.dbErr != nil { if self.dbErr != nil {
fmt.Println("dbErr:", self.dbErr)
return self.dbErr return self.dbErr
} }
root, err := self.trie.CommitTo(dbw) root, err := self.trie.CommitTo(dbw)