From patchwork Mon Mar 3 15:14:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 22906 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 AD924C3257 for ; Mon, 3 Mar 2025 15:14:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B4FAC687EB; Mon, 3 Mar 2025 16:14:42 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jBkkrZgR"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1084168772 for ; Mon, 3 Mar 2025 16:14:41 +0100 (CET) Received: from pb-laptop.local (185.221.143.4.nat.pool.zt.hu [185.221.143.4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 879C22D5 for ; Mon, 3 Mar 2025 16:13:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1741014789; bh=0qFqm/v5COfqSPQ/zKRXVQQzpgwyWs9uCV4ClsTUuU8=; h=From:To:Subject:Date:From; b=jBkkrZgRawJOuqbEN1fv4JhNOgovcQBaw4z+v4P9ELLNrYDGZdbBqwqN2wt8mn/aF pJ0mQUlKPmFNZTX2bjz2v6Rw9JVhyViU16bz+gB7lA3TOGuo4PAr34z+HPDrvQSV23 YEi7i9M1zIzZ0lnlCzqCS0wrwxYjvwOhRazh+jRA= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v1] libcamera: base: bound_method: Forward arguments when possible Date: Mon, 3 Mar 2025 16:14:38 +0100 Message-ID: <20250303151438.732916-1-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 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" Use `std::{forward,move}` to forward the arguments, this enables the use of move constructors, likely leading to less code and better runtime. For example, move constructing a libstdc++ `std::shared_ptr` is noticeably less code than copy constructing one. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart --- include/libcamera/base/bound_method.h | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/include/libcamera/base/bound_method.h b/include/libcamera/base/bound_method.h index dd3488eeb..47e0a2475 100644 --- a/include/libcamera/base/bound_method.h +++ b/include/libcamera/base/bound_method.h @@ -33,8 +33,9 @@ template class BoundMethodPack : public BoundMethodPackBase { public: - BoundMethodPack(const Args &... args) - : args_(args...) + template + BoundMethodPack(Ts &&...args) + : args_(std::forward(args)...) { } @@ -51,8 +52,9 @@ template class BoundMethodPack : public BoundMethodPackBase { public: - BoundMethodPack(const Args &... args) - : args_(args...) + template + BoundMethodPack(Ts &&...args) + : args_(std::forward(args)...) { } @@ -136,23 +138,23 @@ public: BoundMethodFunctor(T *obj, Object *object, Func func, ConnectionType type = ConnectionTypeAuto) - : BoundMethodArgs(obj, object, type), func_(func) + : BoundMethodArgs(obj, object, type), func_(std::move(func)) { } R activate(Args... args, bool deleteMethod = false) override { if (!this->object_) - return func_(args...); + return func_(std::forward(args)...); - auto pack = std::make_shared(args...); + auto pack = std::make_shared(std::forward(args)...); bool sync = BoundMethodBase::activatePack(pack, deleteMethod); return sync ? pack->returnValue() : R(); } R invoke(Args... args) override { - return func_(args...); + return func_(std::forward(args)...); } private: @@ -177,10 +179,10 @@ public: { if (!this->object_) { T *obj = static_cast(this->obj_); - return (obj->*func_)(args...); + return (obj->*func_)(std::forward(args)...); } - auto pack = std::make_shared(args...); + auto pack = std::make_shared(std::forward(args)...); bool sync = BoundMethodBase::activatePack(pack, deleteMethod); return sync ? pack->returnValue() : R(); } @@ -188,7 +190,7 @@ public: R invoke(Args... args) override { T *obj = static_cast(this->obj_); - return (obj->*func_)(args...); + return (obj->*func_)(std::forward(args)...); } private: @@ -209,7 +211,7 @@ public: R activate(Args... args, [[maybe_unused]] bool deleteMethod = false) override { - return (*func_)(args...); + return (*func_)(std::forward(args)...); } R invoke(Args...) override