Skip to content

Commit

Permalink
also cache public account functions
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Nov 18, 2022
1 parent 6a3eacb commit 4e46af8
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions runtime/interpreter/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func NewPublicAccountValue(

var keys Value
var contracts Value
var forEachPublicFunction *HostFunctionValue

computeField := func(name string, inter *Interpreter, locationRange LocationRange) Value {
switch name {
Expand All @@ -264,25 +265,44 @@ func NewPublicAccountValue(
keys = keysConstructor()
}
return keys

case sema.PublicAccountContractsField:
if contracts == nil {
contracts = contractsConstructor()
}
return contracts

case sema.PublicAccountPathsField:
return inter.publicAccountPaths(address, locationRange)

case sema.PublicAccountForEachPublicField:
return inter.newStorageIterationFunction(address, common.PathDomainPublic, sema.PublicPathType)
if forEachPublicFunction == nil {
forEachPublicFunction = inter.newStorageIterationFunction(
address,
common.PathDomainPublic,
sema.PublicPathType,
)
}
return forEachPublicFunction

case sema.PublicAccountBalanceField:
return accountBalanceGet()

case sema.PublicAccountAvailableBalanceField:
return accountAvailableBalanceGet()

case sema.PublicAccountStorageUsedField:
return storageUsedGet(inter)

case sema.PublicAccountStorageCapacityField:
return storageCapacityGet(inter)

case sema.PublicAccountGetTargetLinkField:
return inter.accountGetLinkTargetFunction(address)
var getLinkTargetFunction *HostFunctionValue
if getLinkTargetFunction == nil {
getLinkTargetFunction = inter.accountGetLinkTargetFunction(address)
}
return getLinkTargetFunction
}

return nil
Expand Down

0 comments on commit 4e46af8

Please sign in to comment.