Skip to content
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

Reduce repetition in generated C bindings. #769

Closed
mahesh-hegde opened this issue Sep 7, 2022 · 2 comments
Closed

Reduce repetition in generated C bindings. #769

mahesh-hegde opened this issue Sep 7, 2022 · 2 comments

Comments

@mahesh-hegde
Copy link
Contributor

mahesh-hegde commented Sep 7, 2022

Currently generated code makes heavy use of in-line method calls and error checks. There's a lot of repetition.

FFI_PLUGIN_EXPORT
jobject com_fasterxml_jackson_core_JsonParser_nextToken(jobject self_) {
    load_env();
    load_class_gr(&_c_com_fasterxml_jackson_core_JsonParser, "com/fasterxml/jackson/core/JsonParser");
    if (_c_com_fasterxml_jackson_core_JsonParser == NULL) return (jobject)0;
    load_method(_c_com_fasterxml_jackson_core_JsonParser, &_m_com_fasterxml_jackson_core_JsonParser_nextToken, "nextToken", "()Lcom/fasterxml/jackson/core/JsonToken;");
    if (_m_com_fasterxml_jackson_core_JsonParser_nextToken == NULL) return (jobject)0;
    jobject _result = (*jniEnv)->CallObjectMethod(jniEnv, self_, _m_com_fasterxml_jackson_core_JsonParser_nextToken);
    return to_global_ref(_result);
}

Here, a lot of stuff is repetitive, and will probably inflate the dylib size.

Probably this can be reduced to

FFI_PLUGIN_EXPORT
jobject com_fasterxml_jackson_core_JsonParser_nextToken(jobject self_) {
    CallObjectMethodHelper(
        &_c_com_fasterxml_jackson_core_JsonParser, // variable holding class reference
        "com/fasterxml/jackson/core/JsonParser",          // class name literal
       &_m_com_fasterxml_jackson_core_JsonParser_nextToken, // variable holding a method ID
       "nextToken", "()Lcom/fasterxml/jackson/core/JsonToken;" // method name and signature literals
      self_,
      // possibly next arguments, maybe variadic list.
   );
}

theoretically, the best compression one can achieve is storing the identifying tuple of a method to a table, so nothing is duplicated. But realistically, I think there's some low hanging fruit here.

@mahesh-hegde
Copy link
Contributor Author

cc @dcharkes

Also, related issue regarding generated C code #788. I think that can be fixed along with this.

@mahesh-hegde
Copy link
Contributor Author

Closing this in favor of #660

@HosseinYousefi HosseinYousefi transferred this issue from dart-archive/jnigen Nov 17, 2023
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

No branches or pull requests

1 participant