Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit 1031777

Browse files
Brechtpddong77
authored andcommitted
Optimized bytesToBytes32() (#321)
1 parent aa37577 commit 1031777

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

contracts/lib/BytesUtil.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ library BytesUtil {
3030
pure
3131
returns (bytes32 out)
3232
{
33-
for (uint i = 0; i < 32; i++) {
34-
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
33+
require(b.length >= offset + 32);
34+
bytes32 temp;
35+
assembly {
36+
temp := mload(add(add(b, 0x20), offset))
3537
}
38+
return temp;
3639
}
37-
}
40+
}

0 commit comments

Comments
 (0)