Skip to content

Commit

Permalink
(perf): use a rvalue cast in func_wrapper (pybind#3966)
Browse files Browse the repository at this point in the history
* (perf): use an rvalue cast in func_wrapper

* Try to clarify comment

* Fix comment typo
# Conflicts:
#	include/pybind11/functional.h
  • Loading branch information
EricCousineau-TRI committed Oct 17, 2023
1 parent 36695db commit 7349954
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions include/pybind11/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ struct type_caster<std::function<Return(Args...)>> {
explicit func_wrapper(func_handle &&hf) noexcept : hfunc(std::move(hf)) {}
Return operator()(Args... args) const {
gil_scoped_acquire acq;
object retval(hfunc.f(std::forward<Args>(args)...));
/* Visual studio 2015 parser issue: need parentheses around this expression */
return (retval.template cast<Return>());
// casts the returned object as a rvalue to the return type
return object(hfunc.f(std::forward<Args>(args)...)).template cast<Return>();
}
};

Expand Down

0 comments on commit 7349954

Please sign in to comment.