From patchwork Thu Nov 18 23:45:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 14639 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6B752BDB1C for ; Thu, 18 Nov 2021 23:46:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8D3E460371; Fri, 19 Nov 2021 00:46:17 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uGZlZQvA"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7301760121 for ; Fri, 19 Nov 2021 00:46:15 +0100 (CET) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EA1B41B64 for ; Fri, 19 Nov 2021 00:46:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1637279175; bh=6GUXNdTURbEeOQmfqJNNkGRqOvmxd0HEsjrxqLsNH/o=; h=From:To:Subject:Date:From; b=uGZlZQvAhx4R1inTB2MtM199eoaedUFDOfhYiFVNEcuz/RfTF9m5e8Xrm+ST1jWzI W8uK+gcHFgtZX7Z8Om1OvEehiu74cin1YQwCk2NIgX+QEWCXd3OvSak1tLQHVSpTs1 /N/SOwCj1+Yw/zsfChfUuRfALiR8hX5MaUdUj9fI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 19 Nov 2021 01:45:46 +0200 Message-Id: <20211118234546.9848-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: object: Avoid argument copies in invokeMethod() X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Template argument deduction results in the lvalue and lvalue reference arguments to the invokeMethod() function causing deduction of the Args template type to a non-reference type. This results in the argument being passed by value and copied. Fix this by using a cv-unqualified rvalue reference parameter type. The type is then deduced to an lvalue reference when the argument is an lvalue or lvalue reference, due to a combination of the special template argument deduction rule for rvalue reference parameter types: If P is an rvalue reference to a cv-unqualified template parameter (so-called forwarding reference), and the corresponding function call argument is an lvalue, the type lvalue reference to A is used in place of A for deduction. (https://en.cppreference.com/w/cpp/language/template_argument_deduction) and the reference collapsing rule (https://en.cppreference.com/w/cpp/language/reference#Reference_collapsing). Signed-off-by: Laurent Pinchart Reviewed-by: Umang Jain Reviewed-by: Kieran Bingham --- include/libcamera/base/object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: d9a2a1f703273a28b001dee40fddd378bba7a1b6 diff --git a/include/libcamera/base/object.h b/include/libcamera/base/object.h index 5c385ab4b140..ae2a275caf68 100644 --- a/include/libcamera/base/object.h +++ b/include/libcamera/base/object.h @@ -34,7 +34,7 @@ public: template::value> * = nullptr> R invokeMethod(R (T::*func)(FuncArgs...), ConnectionType type, - Args... args) + Args&&... args) { T *obj = static_cast(this); auto *method = new BoundMethodMember(obj, this, func, type);