Small cleanups (#2414)

* remove unnecessary / expensive error checking
* avoid some trivial memory allocs
* work around table move bug
This commit is contained in:
Jacek Sieka 2024-06-26 09:25:09 +02:00 committed by GitHub
parent cd21c4fbec
commit c8cdffa775
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 11 additions and 16 deletions

View File

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

View File

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

View File

@ -65,7 +65,7 @@ func getOrVoid(tab: Table[VertexID,VertexID]; vid: VertexID): VertexID =
func hasValue( func hasValue(
wffTable: Table[VertexID,VertexID]; wffTable: Table[VertexID,VertexID];
vid: VertexID; vid: VertexID;
wff: WidthFirstForest; wff: var WidthFirstForest;
): bool = ): bool =
## Helper for efficient `value` access: ## Helper for efficient `value` access:
## :: ## ::
@ -75,9 +75,10 @@ func hasValue(
## :: ## ::
## vid in wffTable.values.toSeq ## vid in wffTable.values.toSeq
## ##
for w in wff.rev.getOrVoid vid: wff.rev.withValue(vid, v):
if w in wffTable: for w in v[]:
return true if w in wffTable:
return true
proc pedigree( proc pedigree(

View File

@ -184,7 +184,7 @@ proc retrieveStoAccHike*(
## vertex and the vertex ID. ## vertex and the vertex ID.
## ##
# Expand vertex path to account leaf # 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) return err(UtilsAccInaccessible)
# Extract the account payload fro the leaf # Extract the account payload fro the leaf
@ -192,15 +192,8 @@ proc retrieveStoAccHike*(
if wp.vtx.vType != Leaf: if wp.vtx.vType != Leaf:
return err(UtilsAccPathWithoutLeaf) return err(UtilsAccPathWithoutLeaf)
assert wp.vtx.lData.pType == AccountData # debugging only assert wp.vtx.lData.pType == AccountData # debugging only
let acc = wp.vtx.lData.account
# Check whether storage ID exists, at all ok(move(hike))
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)
proc updateAccountForHasher*( proc updateAccountForHasher*(
db: AristoDbRef; # Database db: AristoDbRef; # Database

View File

@ -695,7 +695,9 @@ proc persist*(ac: AccountsLedgerRef,
if clearCache: if clearCache:
# This overwrites the cache from the previous persist, providing a crude LRU # This overwrites the cache from the previous persist, providing a crude LRU
# scheme with little overhead # 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() ac.savePoint.selfDestruct.clear()