summaryrefslogtreecommitdiff
path: root/Source/Swig/cwrap.c
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2022-07-08 08:34:45 +0100
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2022-07-08 17:41:15 +0100
commite777b054d583aaf2ed445a263208c6ef21bc05ac (patch)
tree071c0ee9d9ee1b36bf648f3d575b51b59087b1a8 /Source/Swig/cwrap.c
parent1ece69cafd417b2936347686df8482a26eadb90e (diff)
downloadswig-e777b054d583aaf2ed445a263208c6ef21bc05ac.tar.gz
Performance optimisation for parameters passed by value that are C++11 movable.
The C++ wrappers create a temporary variable for a parameter to be passed to a function. This is initially default constructed and then copy assigned from the instance being passed in from the target language. This is unchanged, however, when the temporary variable is passed to wrapped function, it is now done using std::move. If the type is move constructible, the move constructor will be used instead of the copy constructor. Note that the implementation calls std::move for all user-defined types (non-primitive types passed by value), this excludes anything passed by pointer, reference and arrays. It does also include any type that has not been defined/parsed by SWIG, that is, unknown types. std::move is called via the SWIG_STD_MOVE macro which only calls std::move for C++11 and later code.
Diffstat (limited to 'Source/Swig/cwrap.c')
-rw-r--r--Source/Swig/cwrap.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c
index ebe9fa702..36e69332c 100644
--- a/Source/Swig/cwrap.c
+++ b/Source/Swig/cwrap.c
@@ -427,10 +427,14 @@ String *Swig_cfunction_call(const_String_or_char_ptr name, ParmList *parms) {
String *rcaststr = SwigType_rcaststr(rpt, pname);
if (comma) {
- Printv(func, ",", rcaststr, NIL);
- } else {
- Append(func, rcaststr);
+ Append(func, ",");
}
+
+ if (cparse_cplusplus && SwigType_type(rpt) == T_USER)
+ Printv(func, "SWIG_STD_MOVE(", rcaststr, ")", NIL);
+ else
+ Printv(func, rcaststr, NIL);
+
Delete(rpt);
Delete(pname);
Delete(rcaststr);