-
Notifications
You must be signed in to change notification settings - Fork 14
Views #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Views #135
Conversation
Jean-Lessa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good to me. This is probably gonna conflict real hard with my optimize branch (I changed a lot of things there, significant breaking changes), but I think it's better to merge this first so we don't have problems with the bigger ContractHost refactoring. I'll handle those conflicts on my end eventually so I can merge my part later on without prejudicing yours.
| using Byte = uint8_t; | ||
|
|
||
| using Bytes = std::vector<Byte>; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Friendly suggestion:
| template <std::size_t N> using BytesArr = std::array<Byte, N>; ///< Typedef for BytesArr. |
This is gonna help me a bit on my optimize branch, been duplicating those lines everywhere
This PR introduces a family of "view" types and new algorithms for byte manipulation.
Changes:
View<Address>,View<Hash>,View<Signature>, andView<Bytes>. In short, they aim to replace a constant reference with a view object, just likestd::string_viewreplacesconst std::string&. For example, aView<Address>can be cheaply created from bothAddressandevmc::addresstypes.SafeHashand the newSafeComparenow allow "transparent search". That means calls to.find()in map objects with different types thanKeyare allowed as long as they are equally comparable with the key type and the hash function accepts them. This is especially useful for theContractHostneeds, where we have maps whose key type isAddress, but often searches useevmc::addressobjects. In this case, we would need to convert (i.e. copy the bytes) from one type to another, but with transparent search a call tofind()with aevmc::addressargument is perfectly valid.Introduced
bytes::random()andbytes::random(size_t)functions. They initialize byte containers with random data. Thebytes::random()matches the container size, while thebytes::random(size_t)can be used where a sized initializer is required.Introduced
bytes::hex()for initializing a container with a hexadecimal string representation. Ex:Address addr = bytes::hex("0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359");Introduced
bytes::cast()function for general-purpose bytes range conversion. For example:HashandView<Hash>can now be converted touint256_tby usingstatic_cast. Example:bytes::Viewdeprecated and replaced byView<Bytes>.strings.hheader broke into multiple header files:fixedbytes.h,signature.h,address.h, andhash.h.