godotengine / godotengine/godot-cpp
godot-cpp: `PtrToArg::convert()` creates unnecessary copies
- Dominant language
- C++
- Stars
- 2.7k
- Forks
- 809
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 8
Description
### Godot version
4.6.stable
### godot-cpp version
master
### System information
linux
### Issue description
The code for `PtrToArg` is pretty old and can be updated to not make copies
```cpp
#define MAKE_PTRARG(m_type) \
template <> \
struct PtrToArg { \
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
return *reinterpret_cast(p_ptr); \
} \
}; \
template <> \
struct PtrToArg { \
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
return *reinterpret_cast(p_ptr); \
} \
}
```
Stumbled upon this while thinking about why we needed internal getter https://github.com/godotengine/godot/pull/99201 , while it does looks like internal getter has its uses the engine itself had a similar issue https://github.com/godotengine/godot/issues/80074 and merged pr that prevented copying, so I figure `godot-cpp` can also stop copying arguments it got by a pointer where it doesn't need to make copies.
Also the engine itself is using even newer `PtrToArgDirect` and `PtrToArgByReference` where it doesn't make copies for arguments that can be passed by reference.
Tbh, it's just an enhancement, as `godot-cpp` will work correctly even without this, but in marshalling less copies is always better
### Steps to reproduce
Bind method with `const T &` argument
### Minimal reproduction project
N/A
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.