Skip to content

Conversation

tdermendjiev
Copy link
Contributor

No description provided.

CachedSignature newSignature;
newSignature.offset = newOffset;

for (size_t i = 0; i < signature.size(); i++) {
Copy link
Contributor

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::Types to vector of FFITypes 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;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants