mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core/vm: add precompile cache
This commit is contained in:
parent
e24017688f
commit
17994c249e
1 changed files with 30 additions and 0 deletions
30
core/vm/contracts_cache.go
Normal file
30
core/vm/contracts_cache.go
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
package vm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/common/lru"
|
||||||
|
)
|
||||||
|
|
||||||
|
var caches map[common.Address]*lru.Cache[string, []byte]
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
caches = make(map[common.Address]*lru.Cache[string, []byte])
|
||||||
|
}
|
||||||
|
|
||||||
|
func addCache(precompile common.Address, input, output []byte) {
|
||||||
|
cache, ok := caches[precompile]
|
||||||
|
if !ok {
|
||||||
|
cache = lru.NewCache[string, []byte](128)
|
||||||
|
caches[precompile] = cache
|
||||||
|
}
|
||||||
|
cache.Add(string(input), output)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getCache(precompile common.Address, input []byte) ([]byte, bool) {
|
||||||
|
cache, ok := caches[precompile]
|
||||||
|
if !ok {
|
||||||
|
caches[precompile] = lru.NewCache[string, []byte](128)
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return cache.Get(string(input))
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue