-
-
Notifications
You must be signed in to change notification settings - Fork 3
Unique function and method signature instances in metadata. #62
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: master
Are you sure you want to change the base?
Conversation
src/Binary/binarySerializer.cpp
Outdated
CachedSignature newSignature; | ||
newSignature.offset = newOffset; | ||
|
||
for (size_t i = 0; i < signature.size(); i++) { |
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.
Since we are mapping Meta::Type
objects to FFIType
values for a second time in the same method I suggest extracting the mapping logic outside of the binary serialization. The mapping logic is not directly related to the binary serialization, it is a property of the Meta::Type
itself. I suggest introducing an instance method of the Meta::Type
structure, mapping the type to a FFIType
:
FFIType toFFIType() const
{
switch (this->type) {
case TypeBool:
return FFYTypeUInt8
case TypeShort:
...
}
Then a MethodMeta
can have a method that converts a vector of Meta::Type
s to vector of FFIType
s e.g.:
std::vector<FFIType> getFFISignature() const
{
...
}
This way the mapping logic will not be extracted from the binary serializer and can be used in other modules without code repetition e.g. it is a good idea to print the FFI signature of a method in the Yaml output.
@@ -15,6 +41,10 @@ class BinarySerializer : public ::Meta::MetaVisitor { | |||
MetaFile* file; | |||
BinaryWriter heapWriter; | |||
BinaryTypeEncodingSerializer typeEncodingSerializer; | |||
|
|||
std::vector<CachedSignature> cachedSignatures; |
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.
Wouldn't it be more efficient to use std::unordered_map<std::vector<FFIType>, MetaFileOffset>
instead of vector? This way the lookup of a signature will be much faster, avoiding the need for iterating over the vector. However, this requires introducing hash
and isEqualTo
operations for std::vector<FFIType>
which IMO should not be so difficult.
1f159b8
to
7c717a5
Compare
No description provided.