-
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
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_view
replacesconst std::string&
. For example, aView<Address>
can be cheaply created from bothAddress
andevmc::address
types.SafeHash
and the newSafeCompare
now allow "transparent search". That means calls to.find()
in map objects with different types thanKey
are allowed as long as they are equally comparable with the key type and the hash function accepts them. This is especially useful for theContractHost
needs, where we have maps whose key type isAddress
, but often searches useevmc::address
objects. 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::address
argument 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:Hash
andView<Hash>
can now be converted touint256_t
by usingstatic_cast
. Example:bytes::View
deprecated and replaced byView<Bytes>
.strings.h
header broke into multiple header files:fixedbytes.h
,signature.h
,address.h
, andhash.h
.