diff options
author | Felix Lange <fjl@twurst.com> | 2016-10-06 04:56:07 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-10-06 21:32:17 +0800 |
commit | 3c836dd71b192de24774b1848173a4eb0ca9a63b (patch) | |
tree | fbd60e1c4ae53c49b7a8e97d3056ae643921f856 | |
parent | 90fce8bfa621f8c3be6663d62740783949111ff1 (diff) | |
download | go-tangerine-3c836dd71b192de24774b1848173a4eb0ca9a63b.tar go-tangerine-3c836dd71b192de24774b1848173a4eb0ca9a63b.tar.gz go-tangerine-3c836dd71b192de24774b1848173a4eb0ca9a63b.tar.bz2 go-tangerine-3c836dd71b192de24774b1848173a4eb0ca9a63b.tar.lz go-tangerine-3c836dd71b192de24774b1848173a4eb0ca9a63b.tar.xz go-tangerine-3c836dd71b192de24774b1848173a4eb0ca9a63b.tar.zst go-tangerine-3c836dd71b192de24774b1848173a4eb0ca9a63b.zip |
core/state: optimize GetState
There is no need to use the reflection-based decoder to decode []byte.
-rw-r--r-- | core/state/state_object.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/core/state/state_object.go b/core/state/state_object.go index a6b6028bc..6eab27d9e 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -153,10 +153,13 @@ func (self *StateObject) GetState(db trie.Database, key common.Hash) common.Hash return value } // Load from DB in case it is missing. - tr := self.getTrie(db) - var ret []byte - rlp.DecodeBytes(tr.Get(key[:]), &ret) - value = common.BytesToHash(ret) + if enc := self.getTrie(db).Get(key[:]); len(enc) > 0 { + _, content, _, err := rlp.Split(enc) + if err != nil { + self.setError(err) + } + value.SetBytes(content) + } if (value != common.Hash{}) { 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 { self.updateTrie(db) if self.dbErr != nil { - fmt.Println("dbErr:", self.dbErr) return self.dbErr } root, err := self.trie.CommitTo(dbw) |