Skip to content

Commit 285f610

Browse files
committed
perf(f02): fold _readBigInt's zero-length guard into assembly
Assisted-by: Claude:claude-sonnet-4-6
1 parent 95f8ef5 commit 285f610

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/lib/FVMRewards.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,12 +536,13 @@ library FVMRewards {
536536
/// @dev A Filecoin BigInt: an empty byte string is zero, otherwise a sign byte followed by a
537537
/// big-endian magnitude. An entitlement is never negative and never exceeds a uint256.
538538
function _readBigInt(uint256 p, uint256 len) private pure returns (uint256 value) {
539-
if (len == 0) return 0;
540539
assembly ("memory-safe") {
541-
let signByte := byte(0, mload(p))
542-
let magLen := sub(len, 1)
543-
if or(signByte, gt(magLen, 32)) { revert(0, 0) }
544-
if magLen { value := shr(shl(3, sub(32, magLen)), mload(add(p, 1))) }
540+
if len {
541+
let signByte := byte(0, mload(p))
542+
let magLen := sub(len, 1)
543+
if or(signByte, gt(magLen, 32)) { revert(0, 0) }
544+
if magLen { value := shr(shl(3, sub(32, magLen)), mload(add(p, 1))) }
545+
}
545546
}
546547
}
547548
}

0 commit comments

Comments
 (0)