You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have data which is read-only in calldata solidity will copy it to memory anyways when passing it to internal/private/public functions.
Motivation
If read-only calldata is copied for memory for no reason (it should only be copied to memory if it is edited - if it is read-only calldata it should never be copied) this wastes gas. If this happens, it should only be read from calldata and not waste gas on copying to memory.
Specification
The public/internal/private function types should allow data (such as bytes or string) to be passed as calldata type. If this data is ever edited in the code, then the compiler should throw since this cannot be compiled: if it is explicitly passed as calldata this data is then read-only. If the user wishes to edit data, they should manually put it into a memory type of data.
Backwards Compatibility
This is incompatible with sol < 0.5 since calldata is not a valid keyword there.
The text was updated successfully, but these errors were encountered:
Note that a prerequisite to this is fully implementing support for calldata types in the first place. For now, only one-dimensional arrays are supported.
For calldata variables we have a similar problem as with storage pointer variables: They cannot be properly auto-initialized and have to be assigned before they can be accessed.
Although it might be useful to auto-initialize them to calldatasize().
Abstract
If I have data which is read-only in calldata solidity will copy it to memory anyways when passing it to internal/private/public functions.
Motivation
If read-only calldata is copied for memory for no reason (it should only be copied to memory if it is edited - if it is read-only calldata it should never be copied) this wastes gas. If this happens, it should only be read from calldata and not waste gas on copying to memory.
Specification
The public/internal/private function types should allow data (such as
bytes
orstring
) to be passed ascalldata
type. If this data is ever edited in the code, then the compiler should throw since this cannot be compiled: if it is explicitly passed as calldata this data is then read-only. If the user wishes to edit data, they should manually put it into amemory
type of data.Backwards Compatibility
This is incompatible with sol < 0.5 since
calldata
is not a valid keyword there.The text was updated successfully, but these errors were encountered: