Skip to content

Commit 9c6a462

Browse files
committed
perf: optimize bitmap conversion + remove shuffle function
1 parent 568f892 commit 9c6a462

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

src/test/integration/IntegrationDeployer.t.sol

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -646,33 +646,17 @@ abstract contract IntegrationDeployer is ExistingDeploymentParser {
646646
return userType;
647647
}
648648

649-
function _shuffle(IStrategy[] memory strats) internal returns (IStrategy[] memory) {
650-
// Fisher-Yates shuffle algorithm
651-
for (uint i = strats.length - 1; i > 0; i--) {
652-
uint randomIndex = _randUint({min: 0, max: i});
653-
654-
// Swap elements
655-
IStrategy temp = strats[i];
656-
strats[i] = strats[randomIndex];
657-
strats[randomIndex] = temp;
658-
}
659-
660-
return strats;
661-
}
662-
663649
/**
664650
* @dev Converts a bitmap into an array of bytes
665651
* @dev Each byte in the input is processed as indicating a single bit to flip in the bitmap
666652
*/
667653
function _bitmapToBytes(uint bitmap) internal pure returns (bytes memory bytesArray) {
668-
for (uint i = 0; i < 256; ++i) {
669-
// Mask for i-th bit
670-
uint mask = uint(1 << i);
671-
672-
// If the i-th bit is flipped, add a byte to the return array
673-
if (bitmap & mask != 0) bytesArray = bytes.concat(bytesArray, bytes1(uint8(1 << i)));
674-
}
675-
return bytesArray;
654+
// Asset type flags
655+
if (bitmap & NO_ASSETS != 0) bytesArray = bytes.concat(bytesArray, bytes1(uint8(1)));
656+
if (bitmap & HOLDS_LST != 0) bytesArray = bytes.concat(bytesArray, bytes1(uint8(2)));
657+
if (bitmap & HOLDS_ETH != 0) bytesArray = bytes.concat(bytesArray, bytes1(uint8(4)));
658+
if (bitmap & HOLDS_ALL != 0) bytesArray = bytes.concat(bytesArray, bytes1(uint8(8)));
659+
if (bitmap & HOLDS_MAX != 0) bytesArray = bytes.concat(bytesArray, bytes1(uint8(16)));
676660
}
677661

678662
function _hash(string memory x) internal pure returns (bytes32) {

0 commit comments

Comments
 (0)