Skip to content

Reduce repetition in generated C bindings. #769

@mahesh-hegde

Description

@mahesh-hegde

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions