Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Dec 29, 2024
1 parent 84ac5dc commit 265c3bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions src/utils/LibBytes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,12 @@ library LibBytes {
for { let i := 0x20 } 1 {} {
let x := mload(add(a, i))
let y := mload(add(b, i))
if or(xor(x, y), eq(i, n)) {
result := sub(gt(x, y), lt(x, y))
break
if iszero(or(xor(x, y), eq(i, n))) {
i := add(i, 0x20)
continue
}
i := add(i, 0x20)
result := sub(gt(x, y), lt(x, y))
break
}
}
// forgefmt: disable-next-item
Expand Down
16 changes: 8 additions & 8 deletions src/utils/g/LibBytes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -628,19 +628,19 @@ library LibBytes {
for { let i := 0x20 } 1 {} {
let x := mload(add(a, i))
let y := mload(add(b, i))
if or(xor(x, y), eq(i, n)) {
result := sub(gt(x, y), lt(x, y))
break
if iszero(or(xor(x, y), eq(i, n))) {
i := add(i, 0x20)
continue
}
i := add(i, 0x20)
result := sub(gt(x, y), lt(x, y))
break
}
}
// forgefmt: disable-next-item
if iszero(result) {
let x := and(mload(add(add(a, 0x20), n)),
not(shr(mul(7, sub(aLen, n)), shr(sub(aLen, n), not(result)))))
let y := and(mload(add(add(b, 0x20), n)),
not(shr(mul(7, sub(bLen, n)), shr(sub(bLen, n), not(result)))))
let l := 0x201f1e1d1c1b1a191817161514131211100f0e0d0c0b0a090807060504030201
let x := and(mload(add(add(a, 0x20), n)), shl(shl(3, byte(sub(aLen, n), l)), not(0)))
let y := and(mload(add(add(b, 0x20), n)), shl(shl(3, byte(sub(bLen, n), l)), not(0)))
result := sub(gt(x, y), lt(x, y))
if iszero(result) { result := sub(gt(aLen, bLen), lt(aLen, bLen)) }
}
Expand Down

0 comments on commit 265c3bd

Please sign in to comment.