{"id":14639,"url":"https://patchwork.libcamera.org/api/patches/14639/?format=json","web_url":"https://patchwork.libcamera.org/patch/14639/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20211118234546.9848-1-laurent.pinchart@ideasonboard.com>","date":"2021-11-18T23:45:46","name":"[libcamera-devel] libcamera: object: Avoid argument copies in invokeMethod()","commit_ref":"0eacde623bb08504c71e18713188a7cfaf4e8e80","pull_url":null,"state":"accepted","archived":false,"hash":"ef2087fd5e628eced1cccedf1fe1aa034d4cae81","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/14639/mbox/","series":[{"id":2729,"url":"https://patchwork.libcamera.org/api/series/2729/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2729","date":"2021-11-18T23:45:46","name":"[libcamera-devel] libcamera: object: Avoid argument copies in invokeMethod()","version":1,"mbox":"https://patchwork.libcamera.org/series/2729/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14639/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14639/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 6B752BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 18 Nov 2021 23:46:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8D3E460371;\n\tFri, 19 Nov 2021 00:46:17 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7301760121\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Nov 2021 00:46:15 +0100 (CET)","from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EA1B41B64\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 19 Nov 2021 00:46:14 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"uGZlZQvA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1637279175;\n\tbh=6GUXNdTURbEeOQmfqJNNkGRqOvmxd0HEsjrxqLsNH/o=;\n\th=From:To:Subject:Date:From;\n\tb=uGZlZQvAhx4R1inTB2MtM199eoaedUFDOfhYiFVNEcuz/RfTF9m5e8Xrm+ST1jWzI\n\tW8uK+gcHFgtZX7Z8Om1OvEehiu74cin1YQwCk2NIgX+QEWCXd3OvSak1tLQHVSpTs1\n\t/N/SOwCj1+Yw/zsfChfUuRfALiR8hX5MaUdUj9fI=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","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","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] libcamera: object: Avoid argument copies\n\tin invokeMethod()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Template argument deduction results in the lvalue and lvalue reference\narguments to the invokeMethod() function causing deduction of the Args\ntemplate type to a non-reference type. This results in the argument\nbeing passed by value and copied.\n\nFix this by using a cv-unqualified rvalue reference parameter type. The\ntype is then deduced to an lvalue reference when the argument is an\nlvalue or lvalue reference, due to a combination of the special template\nargument deduction rule for rvalue reference parameter types:\n\n  If P is an rvalue reference to a cv-unqualified template parameter\n  (so-called forwarding reference), and the corresponding function call\n  argument is an lvalue, the type lvalue reference to A is used in place\n  of A for deduction.\n\n  (https://en.cppreference.com/w/cpp/language/template_argument_deduction)\n\nand the reference collapsing rule\n(https://en.cppreference.com/w/cpp/language/reference#Reference_collapsing).\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n include/libcamera/base/object.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\n\nbase-commit: d9a2a1f703273a28b001dee40fddd378bba7a1b6","diff":"diff --git a/include/libcamera/base/object.h b/include/libcamera/base/object.h\nindex 5c385ab4b140..ae2a275caf68 100644\n--- a/include/libcamera/base/object.h\n+++ b/include/libcamera/base/object.h\n@@ -34,7 +34,7 @@ public:\n \ttemplate<typename T, typename R, typename... FuncArgs, typename... Args,\n \t\t typename std::enable_if_t<std::is_base_of<Object, T>::value> * = nullptr>\n \tR invokeMethod(R (T::*func)(FuncArgs...), ConnectionType type,\n-\t\t       Args... args)\n+\t\t       Args&&... args)\n \t{\n \t\tT *obj = static_cast<T *>(this);\n \t\tauto *method = new BoundMethodMember<T, R, FuncArgs...>(obj, this, func, type);\n","prefixes":["libcamera-devel"]}