Skip to content

Commit

Permalink
Use bytes8 index access (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Beregszaszi <[email protected]>
  • Loading branch information
chriseth and axic authored May 15, 2020
1 parent ef58157 commit 417fdae
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions deposit_contract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,16 @@ contract DepositContract is IDepositContract, ERC165 {
}

function to_little_endian_64(uint64 value) internal pure returns (bytes memory ret) {
// Unrolled the loop here.
ret = new bytes(8);
ret[0] = bytes1(uint8(value));
ret[1] = bytes1(uint8(value >> 8));
ret[2] = bytes1(uint8(value >> 16));
ret[3] = bytes1(uint8(value >> 24));
ret[4] = bytes1(uint8(value >> 32));
ret[5] = bytes1(uint8(value >> 40));
ret[6] = bytes1(uint8(value >> 48));
ret[7] = bytes1(uint8(value >> 56));
bytes8 bytesValue = bytes8(value);
// Byteswapping during copying to bytes.
ret[0] = bytesValue[7];
ret[1] = bytesValue[6];
ret[2] = bytesValue[5];
ret[3] = bytesValue[4];
ret[4] = bytesValue[3];
ret[5] = bytesValue[2];
ret[6] = bytesValue[1];
ret[7] = bytesValue[0];
}
}

0 comments on commit 417fdae

Please sign in to comment.