mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
core/vm: add precompile cache
This commit is contained in:
parent
ec880b1737
commit
759f0100e0
1 changed files with 10 additions and 1 deletions
|
|
@ -1,17 +1,24 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/lru"
|
"github.com/ethereum/go-ethereum/common/lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
var caches map[common.Address]*lru.Cache[string, []byte]
|
var (
|
||||||
|
caches map[common.Address]*lru.Cache[string, []byte]
|
||||||
|
mu sync.RWMutex
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caches = make(map[common.Address]*lru.Cache[string, []byte])
|
caches = make(map[common.Address]*lru.Cache[string, []byte])
|
||||||
}
|
}
|
||||||
|
|
||||||
func addCache(precompile common.Address, input, output []byte) {
|
func addCache(precompile common.Address, input, output []byte) {
|
||||||
|
mu.Lock()
|
||||||
|
defer mu.Unlock()
|
||||||
cache, ok := caches[precompile]
|
cache, ok := caches[precompile]
|
||||||
if !ok {
|
if !ok {
|
||||||
cache = lru.NewCache[string, []byte](128)
|
cache = lru.NewCache[string, []byte](128)
|
||||||
|
|
@ -21,6 +28,8 @@ func addCache(precompile common.Address, input, output []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCache(precompile common.Address, input []byte) ([]byte, bool) {
|
func getCache(precompile common.Address, input []byte) ([]byte, bool) {
|
||||||
|
mu.RLock()
|
||||||
|
defer mu.RUnlock()
|
||||||
cache, ok := caches[precompile]
|
cache, ok := caches[precompile]
|
||||||
if !ok {
|
if !ok {
|
||||||
caches[precompile] = lru.NewCache[string, []byte](128)
|
caches[precompile] = lru.NewCache[string, []byte](128)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue