Guest User

Untitled

a guest
Nov 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. // This function is less efficient because the optimizer currently fails to
  2. // remove the bounds checks in array access.
  3.  
  4. function sumSolidity(uint[] _data) returns (uint o_sum) {
  5. for (uint i = 0; i < _data.length; ++i)
  6. o_sum += _data[i];
  7. }
  8.  
  9. // We know that we only access the array in bounds, so we can avoid the check.
  10. // 0x20 needs to be added to an array because the first slot contains the
  11. // array length.
  12.  
  13. function sumAsm(uint[] _data) returns (uint o_sum) {
  14. for (uint i = 0; i < _data.length; ++i) {
  15. assembly {
  16. o_sum := add(o_sum, mload(add(add(_data, 0x20), mul(i, 0x20))))
  17. }
  18. }
  19. }
  20.  
  21. struct MyStruct {
  22. uint256 var_1;
  23. uint256 var_2;
  24. address addr_1;
  25. }
Add Comment
Please, Sign In to add comment