From a2e1e5aef01215325c72640c53934d13caabd5cd Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 15 May 2020 18:47:21 +0200 Subject: [PATCH] Use bytes8 index access (#19) Co-authored-by: Alex Beregszaszi --- deposit_contract.sol | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/deposit_contract.sol b/deposit_contract.sol index 2c2231ffe..8b0693cc2 100644 --- a/deposit_contract.sol +++ b/deposit_contract.sol @@ -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]; } }