(this is for the case when removed element is not already the last one)
This method requires fewer operations and hence less gas, however the order of elements is not preserved. But it doesn't seem to be important, since they can be ordered by creation block anyway.
(Refactor)
proposal (i.e. no new features or updates, just code optimization/library updates)https://github.com/poanetwork/poa-popa/blob/master/blockchain/contracts/ProofOfPhysicalAddress.sol#L341
In current implementation when address is removed by a user, elements of
physicalAddresses
array are shifted and then the last element is deleted:Suggestion is to copy the last element of array to the place of the removed element, then delete the last element:
(this is for the case when removed element is not already the last one)
This method requires fewer operations and hence less gas, however the order of elements is not preserved. But it doesn't seem to be important, since they can be ordered by creation block anyway.
@fvictorio @matiasgaratortiz what do you think?