From patchwork Mon Mar 31 14:17:13 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: 23071 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 CB3DAC323E for ; Mon, 31 Mar 2025 14:17:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5530668989; Mon, 31 Mar 2025 16:17:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="R6i7yfNU"; 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 CE7056897A for ; Mon, 31 Mar 2025 16:17:21 +0200 (CEST) Received: from pb-laptop.local (185.221.143.221.nat.pool.zt.hu [185.221.143.221]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4049082A for ; Mon, 31 Mar 2025 16:15:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1743430530; bh=mDKs3DsA+6gULCwnaECzJszzkhmD/iBQI9xcY2dhuYs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=R6i7yfNUG0P9PA+bbvReUZQbt8Tggegc0Q/1EbaplU9ah+4F6I9isO1Tufm3frJ+l kqPkBrhBX857ZvcdBcHrKTgITYY/CiqXPfuH08tqNu8CABVEsALDRM2oNLBeb0h+lK 1oF7jfULVm2fs59ThINqL6Hv9irqK3ivLNZZ47sM= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 2/3] libcamera: request: Avoid double map lookup Date: Mon, 31 Mar 2025 16:17:13 +0200 Message-ID: <20250331141714.512538-2-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250331141714.512538-1-barnabas.pocze@ideasonboard.com> References: <20250331141714.512538-1-barnabas.pocze@ideasonboard.com> 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 `try_emplace()` that more or less combines `find()` and `operator[]` in one function. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- src/libcamera/request.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index e7eb1c0c8..fc364441a 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -475,15 +475,14 @@ int Request::addBuffer(const Stream *stream, FrameBuffer *buffer, return -EEXIST; } - auto it = bufferMap_.find(stream); - if (it != bufferMap_.end()) { + auto [it, inserted] = bufferMap_.try_emplace(stream, buffer); + if (!inserted) { LOG(Request, Error) << "FrameBuffer already set for stream"; return -EEXIST; } buffer->_d()->setRequest(this); _d()->pending_.insert(buffer); - bufferMap_[stream] = buffer; if (fence && fence->isValid()) buffer->_d()->setFence(std::move(fence));