The referenced ternary condition is meant to assign the last element of the array to the index of the element being removed, however, this will be done inefficiently so when the index being removed is the endPosition.
We advise the code to immediately invoke _deleteLastPositionData if the index is equal to the endPosition without fetching the position token by index nor assigning it at the index, greatly reducing the worst-case gas cost of the function.
MHR-06C: Potentially Inefficient Array Shift Operation
Description:
The referenced ternary condition is meant to assign the last element of the array to the
index
of the element being removed, however, this will be done inefficiently so when theindex
being removed is theendPosition
.Example:
Recommendation:
We advise the code to immediately invoke
_deleteLastPositionData
if theindex
is equal to theendPosition
without fetching the position token by index nor assigning it at theindex
, greatly reducing the worst-case gas cost of the function.