Skip to content

Commit 8d6294f

Browse files
ZumZoomernestognw
andauthored
Optimize Math.average with unchecked math (#6019)
Co-authored-by: Ernesto García <[email protected]>
1 parent 51ab591 commit 8d6294f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

contracts/utils/math/Math.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ library Math {
168168
* zero.
169169
*/
170170
function average(uint256 a, uint256 b) internal pure returns (uint256) {
171-
// (a + b) / 2 can overflow.
172-
return (a & b) + (a ^ b) / 2;
171+
unchecked {
172+
// (a + b) / 2 can overflow.
173+
return (a & b) + (a ^ b) / 2;
174+
}
173175
}
174176

175177
/**

0 commit comments

Comments
 (0)