From 232743c332f9db6b4ee0f0e95e459eb2bff75b02 Mon Sep 17 00:00:00 2001 From: eboado Date: Wed, 28 Oct 2020 12:02:40 +0100 Subject: [PATCH] - Cached _reservesCount on _addReserveToList() --- contracts/lendingpool/LendingPool.sol | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index c63ff348..3f490365 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -913,13 +913,16 @@ contract LendingPool is VersionedInitializable, ILendingPool, LendingPoolStorage * @dev adds a reserve to the array of the _reserves address **/ function _addReserveToList(address asset) internal { - require(_reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED); + + uint256 reservesCount = _reservesCount; + + require(reservesCount < MAX_NUMBER_RESERVES, Errors.NO_MORE_RESERVES_ALLOWED); bool reserveAlreadyAdded = _reserves[asset].id != 0 || _reservesList[0] == asset; if (!reserveAlreadyAdded) { - _reserves[asset].id = uint8(_reservesCount); - _reservesList[_reservesCount] = asset; + _reserves[asset].id = uint8(reservesCount); + _reservesList[reservesCount] = asset; _reservesCount++; }