Skip to content

Commit c42414d

Browse files
authored
(perf): use a rvalue cast in func_wrapper (#3966)
* (perf): use an rvalue cast in func_wrapper * Try to clarify comment * Fix comment typo
1 parent 918d448 commit c42414d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/pybind11/functional.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ struct type_caster<std::function<Return(Args...)>> {
9898
explicit func_wrapper(func_handle &&hf) noexcept : hfunc(std::move(hf)) {}
9999
Return operator()(Args... args) const {
100100
gil_scoped_acquire acq;
101-
object retval(hfunc.f(std::forward<Args>(args)...));
102-
return retval.template cast<Return>();
101+
// casts the returned object as a rvalue to the return type
102+
return object(hfunc.f(std::forward<Args>(args)...)).template cast<Return>();
103103
}
104104
};
105105

0 commit comments

Comments
 (0)