From 172b7894bebc42b2fe5dd13b0d9107a0605d2053 Mon Sep 17 00:00:00 2001 From: Brecht Date: Sun, 22 Apr 2018 17:58:25 +0200 Subject: [PATCH] Optimized bytesToBytes32() --- contracts/lib/BytesUtil.sol | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/lib/BytesUtil.sol b/contracts/lib/BytesUtil.sol index cf474fba..5c3ec22f 100644 --- a/contracts/lib/BytesUtil.sol +++ b/contracts/lib/BytesUtil.sol @@ -30,8 +30,11 @@ library BytesUtil { pure returns (bytes32 out) { - for (uint i = 0; i < 32; i++) { - out |= bytes32(b[offset + i] & 0xFF) >> (i * 8); + require(b.length >= offset + 32); + bytes32 temp; + assembly { + temp := mload(add(add(b, 0x20), offset)) } + return temp; } -} \ No newline at end of file +}