Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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