Skip to content

Commit

Permalink
Optimized mask creation in draw calc (#215)
Browse files Browse the repository at this point in the history
* Optimized mask creation in draw calc

* opt even further

Co-authored-by: Aodhgan <aodhgan@pooltogether.com>
  • Loading branch information
asselstine and Aodhgan committed Oct 14, 2021
1 parent 8483ce5 commit 9d0ca8e
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions contracts/DrawCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,11 @@ contract DrawCalculator is IDrawCalculator, Ownable {
returns (uint256[] memory)
{
uint256[] memory masks = new uint256[](_prizeDistribution.matchCardinality);
uint256 _bitRangeMaskValue = (2**_prizeDistribution.bitRangeSize) - 1; // get a decimal representation of bitRangeSize
masks[0] = (2**_prizeDistribution.bitRangeSize) - 1;

for (uint8 maskIndex = 0; maskIndex < _prizeDistribution.matchCardinality; maskIndex++) {
// create mask of width bitRangeSize bits at index
uint256 _matchIndexOffset = uint256(maskIndex) * uint256(_prizeDistribution.bitRangeSize);
for (uint8 maskIndex = 1; maskIndex < _prizeDistribution.matchCardinality; maskIndex++) {
// shift mask bits to correct position and insert in result mask array
masks[maskIndex] = _bitRangeMaskValue << _matchIndexOffset;
masks[maskIndex] = masks[maskIndex - 1] << _prizeDistribution.bitRangeSize;
}

return masks;
Expand Down

0 comments on commit 9d0ca8e

Please sign in to comment.