Small cleanups

* remove unnecessary / expensive error checking
* avoid some trivial memory allocs
* work around table move bug
This commit is contained in:
Jacek Sieka 2024-06-25 23:45:14 +02:00
parent 3e001e322c
commit 004629fd8b
No known key found for this signature in database
GPG Key ID: A1B09461ABB656B8
5 changed files with 11 additions and 16 deletions

View File

@ -13,7 +13,7 @@
##
import
std/[sequtils, tables],
std/tables,
eth/common,
results,
./aristo_desc,

View File

@ -303,7 +303,6 @@ type
UtilsAccVtxUnsupported
UtilsAccWrongStorageRoot
UtilsPayloadTypeUnsupported
UtilsStoRootInaccessible
UtilsStoRootMissing
# End

View File

@ -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(

View File

@ -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

View File

@ -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()