From c42414db86d393aaea8b450d987f0f56c2c66bca Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 23 May 2022 12:26:53 -0400 Subject: [PATCH] (perf): use a rvalue cast in func_wrapper (#3966) * (perf): use an rvalue cast in func_wrapper * Try to clarify comment * Fix comment typo --- include/pybind11/functional.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index 23e092e73..f2a752e9d 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -98,8 +98,8 @@ public: 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)...)); - return retval.template cast(); + // casts the returned object as a rvalue to the return type + return object(hfunc.f(std::forward(args)...)).template cast(); } };