vector_to_slice_optimization.sol 485 B

1234567891011121314151617181920
  1. contract test {
  2. function can_be_slice() public {
  3. // v can just be a pointer to constant memory and an a length indicator
  4. string v = "Hello, World!";
  5. print(v);
  6. }
  7. function must_be_vector() public {
  8. // if v is a vector, then it needs to allocated and default value copied.
  9. string v = "Hello, World!";
  10. // bs is copied by reference is now modifyable
  11. bytes bs = bytes(v);
  12. bs[1] = 97;
  13. print(v);
  14. }
  15. }