From patchwork Sat Nov 26 23:42:27 2022 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: 17900 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 07D62BDE6B for ; Sat, 26 Nov 2022 23:42:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EED5C6332B; Sun, 27 Nov 2022 00:42:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1669506154; bh=dLM3dVvf1/NKZneAdyTJLCJz1pBc2XBZ127jcLqoguw=; h=Date:To:List-Id:List-Post:From:List-Subscribe:List-Unsubscribe: List-Archive:Reply-To:List-Help:Subject:From; b=qDTpjPnan2rho96hQ2JSC8xnZkM8SmcidMShYpJ1SagVY4X1mjKHsugYlhLoK+2// wePgX7eANEhQj1l4CZRvbqLsSw07ZlZRLE5LEcrZFXWFNZf9SB2HJrHPGo55ACLnVv YppSIQyj5qxkjcBvG9wgAuFqc5D5z9cnAe9bgXH+fSc8apOnCDVpjH5GrSfDOm7txB 6ZrA2RxgDJ5lITTrEUyAl72vKFYAR/VdrNowCRkadS6NsqG64Q07HOg6MeB9L47wNj Nhuaw8035cOLqKKRY8DcSMDxKxZVkV1tV9l6eFKbBVlHJq89Q8HUPMXXGo41roGsD7 AJItAZ8ebG2qw== Date: Sat, 26 Nov 2022 23:42:27 +0000 To: libcamera-devel@lists.libcamera.org MIME-Version: 1.0 Message-ID: List-Id: List-Post: X-Patchwork-Original-From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze_via_libcamera-devel?= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Precedence: list X-Mailman-Version: 2.1.29 X-BeenThere: libcamera-devel@lists.libcamera.org List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= List-Help: Subject: [libcamera-devel] [PATCH v1] libcamera: framebuffer_allocator: Avoid double map lookup Content-Disposition: inline Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use `try_emplace()` on the map instead of `count()` and `operator[]` to avoid walking the tree twice. Signed-off-by: Barnabás Pőcze Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/framebuffer_allocator.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.38.1 diff --git a/src/libcamera/framebuffer_allocator.cpp b/src/libcamera/framebuffer_allocator.cpp index 4df27cac..17c5db49 100644 --- a/src/libcamera/framebuffer_allocator.cpp +++ b/src/libcamera/framebuffer_allocator.cpp @@ -88,12 +88,14 @@ FrameBufferAllocator::~FrameBufferAllocator() */ int FrameBufferAllocator::allocate(Stream *stream) { - if (buffers_.count(stream)) { + const auto &[ it, inserted ] = buffers_.try_emplace(stream); + + if (!inserted) { LOG(Allocator, Error) << "Buffers already allocated for stream"; return -EBUSY; } - int ret = camera_->exportFrameBuffers(stream, &buffers_[stream]); + int ret = camera_->exportFrameBuffers(stream, &it->second); if (ret == -EINVAL) LOG(Allocator, Error) << "Stream is not part of " << camera_->id()