Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This function is less efficient because the optimizer currently fails to
- // remove the bounds checks in array access.
- function sumSolidity(uint[] _data) returns (uint o_sum) {
- for (uint i = 0; i < _data.length; ++i)
- o_sum += _data[i];
- }
- // We know that we only access the array in bounds, so we can avoid the check.
- // 0x20 needs to be added to an array because the first slot contains the
- // array length.
- function sumAsm(uint[] _data) returns (uint o_sum) {
- for (uint i = 0; i < _data.length; ++i) {
- assembly {
- o_sum := add(o_sum, mload(add(add(_data, 0x20), mul(i, 0x20))))
- }
- }
- }
- struct MyStruct {
- uint256 var_1;
- uint256 var_2;
- address addr_1;
- }
Add Comment
Please, Sign In to add comment