Skip to content

Commit

Permalink
Avoid assigning function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzrv committed Oct 26, 2020
1 parent 9f939c9 commit c80793d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions contracts/0.4.24/DePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {

uint256 totalDepositCalls = 0;
uint256 maxDepositCalls = getDepositIterationLimit();
while (_amount != 0 && totalDepositCalls < maxDepositCalls) {
uint256 depositAmount = _amount;
while (depositAmount != 0 && totalDepositCalls < maxDepositCalls) {
// Finding the best suitable SP
uint256 bestSPidx = cache.length; // 'not found' flag
uint256 smallestStake;
Expand All @@ -471,7 +472,7 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
break;

// Invoking deposit for the best SP
_amount = _amount.sub(DEPOSIT_SIZE);
depositAmount = depositAmount.sub(DEPOSIT_SIZE);
++totalDepositCalls;

(bytes memory key, bytes memory signature, bool used) = /* solium-disable-line */
Expand Down Expand Up @@ -729,12 +730,13 @@ contract DePool is IDePool, IsContract, Pausable, AragonApp {
*/
function _toLittleEndian64(uint256 _value) internal pure returns (uint256 result) {
result = 0;
uint256 temp_value = _value;
for (uint256 i = 0; i < 8; ++i) {
result = (result << 8) | (_value & 0xFF);
_value >>= 8;
result = (result << 8) | (temp_value & 0xFF);
temp_value >>= 8;
}

assert(0 == _value); // fully converted
assert(0 == temp_value); // fully converted
result <<= (24 * 8);
}

Expand Down
7 changes: 4 additions & 3 deletions contracts/0.4.24/oracle/BitOps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ library BitOps {
*/
function popcnt(uint256 _mask) internal pure returns (uint256) {
uint256 result = 0;
uint256 tmp_mask = _mask;
for (uint256 i = 0; i < 256; ++i) {
if (1 == _mask & 1) {
if (1 == tmp_mask & 1) {
result++;
}
_mask >>= 1;
tmp_mask >>= 1;
}

assert(0 == _mask);
assert(0 == tmp_mask);
return result;
}
}

0 comments on commit c80793d

Please sign in to comment.