ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
22.65k stars 5.61k forks source link

Optimize resizeDynamicArray #15176

Open molly-ting opened 3 weeks ago

molly-ting commented 3 weeks ago

Description

https://github.com/ethereum/solidity/blob/cb1d21a9de839ce7c7a156f5364ac8877d7be41a/libsolidity/codegen/ArrayUtils.cpp#L642-L750 The two branches of the conditional jump at line 725 both pop the top elements, indicating that the top element is redundant. I noticed that the top element was introduced by the sload at line 672. It seems that this sloaded value is only used in the two branches of the conditional jump at line 679. Why not move this dup3 and sload before line 678? Besides, I tried pushing and popping to a dynamic string array, using new to resize the dynamic array, and using sstore to set the length slot. None of these reached this function. After searching the whole program, I found that this function is not invoked anywhere. Is this function still in use? If not, why not delete it?