Skip to content

Commit 1e7ca3e

Browse files
authored
Remove redundant array access in Checkpoints (#5169)
1 parent 3761947 commit 1e7ca3e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

contracts/utils/structs/Checkpoints.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ library Checkpoints {
142142

143143
// Update or push new checkpoint
144144
if (lastKey == key) {
145-
_unsafeAccess(self, pos - 1)._value = value;
145+
last._value = value;
146146
} else {
147147
self.push(Checkpoint224({_key: key, _value: value}));
148148
}
@@ -337,7 +337,7 @@ library Checkpoints {
337337

338338
// Update or push new checkpoint
339339
if (lastKey == key) {
340-
_unsafeAccess(self, pos - 1)._value = value;
340+
last._value = value;
341341
} else {
342342
self.push(Checkpoint208({_key: key, _value: value}));
343343
}
@@ -532,7 +532,7 @@ library Checkpoints {
532532

533533
// Update or push new checkpoint
534534
if (lastKey == key) {
535-
_unsafeAccess(self, pos - 1)._value = value;
535+
last._value = value;
536536
} else {
537537
self.push(Checkpoint160({_key: key, _value: value}));
538538
}

scripts/generate/templates/Checkpoints.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function _insert(${opts.checkpointTypeName}[] storage self, ${opts.keyTypeName}
147147
148148
// Update or push new checkpoint
149149
if (lastKey == key) {
150-
_unsafeAccess(self, pos - 1).${opts.valueFieldName} = value;
150+
last.${opts.valueFieldName} = value;
151151
} else {
152152
self.push(${opts.checkpointTypeName}({${opts.keyFieldName}: key, ${opts.valueFieldName}: value}));
153153
}

0 commit comments

Comments
 (0)