Small cleanups
* remove unnecessary / expensive error checking * avoid some trivial memory allocs * work around table move bug
This commit is contained in:
parent
3e001e322c
commit
004629fd8b
|
@ -13,7 +13,7 @@
|
|||
##
|
||||
|
||||
import
|
||||
std/[sequtils, tables],
|
||||
std/tables,
|
||||
eth/common,
|
||||
results,
|
||||
./aristo_desc,
|
||||
|
|
|
@ -303,7 +303,6 @@ type
|
|||
UtilsAccVtxUnsupported
|
||||
UtilsAccWrongStorageRoot
|
||||
UtilsPayloadTypeUnsupported
|
||||
UtilsStoRootInaccessible
|
||||
UtilsStoRootMissing
|
||||
|
||||
# End
|
||||
|
|
|
@ -65,7 +65,7 @@ func getOrVoid(tab: Table[VertexID,VertexID]; vid: VertexID): VertexID =
|
|||
func hasValue(
|
||||
wffTable: Table[VertexID,VertexID];
|
||||
vid: VertexID;
|
||||
wff: WidthFirstForest;
|
||||
wff: var WidthFirstForest;
|
||||
): bool =
|
||||
## Helper for efficient `value` access:
|
||||
## ::
|
||||
|
@ -75,9 +75,10 @@ func hasValue(
|
|||
## ::
|
||||
## vid in wffTable.values.toSeq
|
||||
##
|
||||
for w in wff.rev.getOrVoid vid:
|
||||
if w in wffTable:
|
||||
return true
|
||||
wff.rev.withValue(vid, v):
|
||||
for w in v[]:
|
||||
if w in wffTable:
|
||||
return true
|
||||
|
||||
|
||||
proc pedigree(
|
||||
|
|
|
@ -184,7 +184,7 @@ proc retrieveStoAccHike*(
|
|||
## vertex and the vertex ID.
|
||||
##
|
||||
# Expand vertex path to account leaf
|
||||
let hike = accPath.to(NibblesBuf).hikeUp(VertexID(1), db).valueOr:
|
||||
var hike = accPath.to(NibblesBuf).hikeUp(VertexID(1), db).valueOr:
|
||||
return err(UtilsAccInaccessible)
|
||||
|
||||
# Extract the account payload fro the leaf
|
||||
|
@ -192,15 +192,8 @@ proc retrieveStoAccHike*(
|
|||
if wp.vtx.vType != Leaf:
|
||||
return err(UtilsAccPathWithoutLeaf)
|
||||
assert wp.vtx.lData.pType == AccountData # debugging only
|
||||
let acc = wp.vtx.lData.account
|
||||
|
||||
# Check whether storage ID exists, at all
|
||||
if acc.storageID.isValid:
|
||||
# Verify that the storage root `acc.storageID` exists on the databse
|
||||
discard db.getVtxRc(acc.storageID).valueOr:
|
||||
return err(UtilsStoRootInaccessible)
|
||||
|
||||
ok(hike)
|
||||
ok(move(hike))
|
||||
|
||||
proc updateAccountForHasher*(
|
||||
db: AristoDbRef; # Database
|
||||
|
|
|
@ -695,7 +695,9 @@ proc persist*(ac: AccountsLedgerRef,
|
|||
if clearCache:
|
||||
# This overwrites the cache from the previous persist, providing a crude LRU
|
||||
# scheme with little overhead
|
||||
ac.cache = move(ac.savePoint.cache)
|
||||
# TODO https://github.com/nim-lang/Nim/issues/23759
|
||||
swap(ac.cache, ac.savePoint.cache)
|
||||
ac.savePoint.cache.reset()
|
||||
|
||||
ac.savePoint.selfDestruct.clear()
|
||||
|
||||
|
|
Loading…
Reference in New Issue