Open
Conversation
fcecin
approved these changes
Nov 8, 2024
Jean-Lessa
requested changes
Nov 8, 2024
Collaborator
Jean-Lessa
left a comment
There was a problem hiding this comment.
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>; | ||
|
|
Collaborator
There was a problem hiding this comment.
Friendly suggestion:
Suggested change
| 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
fcecin
approved these changes
Dec 23, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.