Skip to content

Commit bd2663f

Browse files
perf: avoid binary search (#1417)
**Motivation:** Small optimization found. **Modifications:** Checks whether a strategy has already been added via .set() return value rather than a separate .contains() check. **Result:** More optimal code.
1 parent 94ad76c commit bd2663f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/contracts/core/StrategyManager.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,17 @@ contract StrategyManager is
153153
IStrategy strategy,
154154
uint256 sharesToBurn
155155
) external onlyDelegationManager nonReentrant {
156+
// Create storage pointer for readability.
156157
EnumerableMap.AddressToUintMap storage burnOrRedistributableShares =
157158
_burnOrRedistributableShares[operatorSet.key()][slashId];
158159

159160
// Sanity check that the strategy is not already in the slash's burn or redistributable shares.
160161
// This should never happen because the `AllocationManager` ensures that strategies for a given slash are unique.
161-
require(!burnOrRedistributableShares.contains(address(strategy)), StrategyAlreadyInSlash());
162-
163162
// Add the shares to the operator set's burn or redistributable shares.
164-
burnOrRedistributableShares.set(address(strategy), sharesToBurn);
163+
require(burnOrRedistributableShares.set(address(strategy), sharesToBurn), StrategyAlreadyInSlash());
165164

166165
// Notify the `SlashEscrowFactory` contract that it received underlying tokens to burn or redistribute.
167166
slashEscrowFactory.initiateSlashEscrow(operatorSet, slashId, strategy);
168-
169167
emit BurnOrRedistributableSharesIncreased(operatorSet, slashId, strategy, sharesToBurn);
170168
}
171169

0 commit comments

Comments
 (0)