From a5ed318634016a25be4000ee07044a31f363e60c Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Sat, 26 Aug 2023 01:17:32 +0200 Subject: [PATCH] Refactor access to Checkpoint struct without using memory (#4512) --- .../governance/extensions/GovernorVotesQuorumFraction.sol | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contracts/governance/extensions/GovernorVotesQuorumFraction.sol b/contracts/governance/extensions/GovernorVotesQuorumFraction.sol index f7def8529..774bff6b1 100644 --- a/contracts/governance/extensions/GovernorVotesQuorumFraction.sol +++ b/contracts/governance/extensions/GovernorVotesQuorumFraction.sol @@ -49,9 +49,11 @@ abstract contract GovernorVotesQuorumFraction is GovernorVotes { uint256 length = _quorumNumeratorHistory._checkpoints.length; // Optimistic search, check the latest checkpoint - Checkpoints.Checkpoint224 memory latest = _quorumNumeratorHistory._checkpoints[length - 1]; - if (latest._key <= timepoint) { - return latest._value; + Checkpoints.Checkpoint224 storage latest = _quorumNumeratorHistory._checkpoints[length - 1]; + uint32 latestKey = latest._key; + uint224 latestValue = latest._value; + if (latestKey <= timepoint) { + return latestValue; } // Otherwise, do the binary search