[OCaml] Cache the result of caml_named_value() in some cases

The result of caml_named_value() can be cached for (slightly)
improved performance.

This is mentioned in the OCaml reference manual.
https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec453

In addition, fix incorrect use of CAMLreturn() in
caml_ptr_val_internal().
This commit is contained in:
Zackery Spytz 2019-02-03 17:37:46 -07:00
commit bdc038b578
2 changed files with 15 additions and 12 deletions

View file

@ -1595,10 +1595,12 @@ public:
/* wrap complex arguments to values */
Printv(w->code, wrap_args, NIL);
/* pass the method call on to the Python object */
/* pass the method call on to the OCaml object */
Printv(w->code,
"swig_result = caml_swig_alloc(1,C_list);\n" "SWIG_Store_field(swig_result,0,args);\n" "args = swig_result;\n" "swig_result = Val_unit;\n", 0);
Printf(w->code, "swig_result = " "caml_callback3(*caml_named_value(\"swig_runmethod\")," "swig_get_self(),caml_copy_string(\"%s\"),args);\n", Getattr(n, "name"));
Printf(w->code, "static CAML_VALUE *swig_ocaml_func_val = NULL;\n" "if (!swig_ocaml_func_val) {\n");
Printf(w->code, " swig_ocaml_func_val = caml_named_value(\"swig_runmethod\");\n }\n");
Printf(w->code, "swig_result = caml_callback3(*swig_ocaml_func_val,swig_get_self(),caml_copy_string(\"%s\"),args);\n", Getattr(n, "name"));
/* exception handling */
tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0);
if (!tm) {