From patchwork Sat Jan 11 11:47:41 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: 22523 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 A6368C32F9 for ; Sat, 11 Jan 2025 11:47:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD026684EA; Sat, 11 Jan 2025 12:47:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=protonmail.com header.i=@protonmail.com header.b="xwsgmJTL"; dkim-atps=neutral Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 60723684D0 for ; Sat, 11 Jan 2025 12:47:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1736596064; x=1736855264; bh=OF4S+iPihvh6yurMp6DRmIJDSMM0dkSg6BGEGdgufpI=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=xwsgmJTLz1JWXr9u0ow3UvGMDUF81f5Mz2vo7PW5wAD601sJXGcdqxHuzyzHkjBQx bb17Dy2voNpYaaL0YWIBzCaq2aevBdyswKA6I4O+jreoxvC3uqDHUS9oKQt2+y9902 +2qymdv4AqVPzc1jvLE++MHWg/GGLxdjzGJHv1ucPjXLcRqCOrVxICuEIyudfiHqTt hVYreU5eE5zJdONGiCDwz4s+DHvj5RC8cL+YZZcXUTfOHlpZplKJpdDasL3WXMWGEf jc9xlfVznl6HEbluOJOgo0c9VpYThcflXjUUHH7ugcQYah77n86QsF7n0Oo1e/NWf8 l7UgmopwcPjSw== Date: Sat, 11 Jan 2025 11:47:41 +0000 To: libcamera-devel@lists.libcamera.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1] pipeline: rkisp1: Avoid unnecessary indirection in `std::map` Message-ID: <20250111114739.170891-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton X-Pm-Message-ID: 14f321d859b4d9909ef1315a646920b93b9a6ca0 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" There is no reason to allocate the `RkISP1FrameInfo` objects dynamically, and then store raw pointers in the `std::map`. Instead, store the objects directly in the map. This removes the need for manully calling new/delete, simplifies the code, and eliminates one memory allocation per frame. Signed-off-by: Barnabás Pőcze Reviewed-by: Kieran Bingham --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 76 +++++++++++------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 35c793da9..111acc35b 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -84,7 +84,7 @@ public: private: PipelineHandlerRkISP1 *pipe_; - std::map frameInfo_; + std::map frameInfo_; }; class RkISP1CameraData : public Camera::Private @@ -269,49 +269,45 @@ RkISP1FrameInfo *RkISP1Frames::create(const RkISP1CameraData *data, Request *req mainPathBuffer = request->findBuffer(&data->mainPathStream_); selfPathBuffer = request->findBuffer(&data->selfPathStream_); - RkISP1FrameInfo *info = new RkISP1FrameInfo; + auto [it, inserted] = frameInfo_.try_emplace(frame); + ASSERT(inserted); - info->frame = frame; - info->request = request; - info->paramBuffer = paramBuffer; - info->mainPathBuffer = mainPathBuffer; - info->selfPathBuffer = selfPathBuffer; - info->statBuffer = statBuffer; - info->paramDequeued = false; - info->metadataProcessed = false; + auto &info = it->second; - frameInfo_[frame] = info; + info.frame = frame; + info.request = request; + info.paramBuffer = paramBuffer; + info.mainPathBuffer = mainPathBuffer; + info.selfPathBuffer = selfPathBuffer; + info.statBuffer = statBuffer; + info.paramDequeued = false; + info.metadataProcessed = false; - return info; + return &info; } int RkISP1Frames::destroy(unsigned int frame) { - RkISP1FrameInfo *info = find(frame); - if (!info) + auto it = frameInfo_.find(frame); + if (it == frameInfo_.end()) return -ENOENT; - pipe_->availableParamBuffers_.push(info->paramBuffer); - pipe_->availableStatBuffers_.push(info->statBuffer); - pipe_->availableMainPathBuffers_.push(info->mainPathBuffer); - - frameInfo_.erase(info->frame); + auto &info = it->second; + pipe_->availableParamBuffers_.push(info.paramBuffer); + pipe_->availableStatBuffers_.push(info.statBuffer); + pipe_->availableMainPathBuffers_.push(info.mainPathBuffer); - delete info; + frameInfo_.erase(it); return 0; } void RkISP1Frames::clear() { - for (const auto &entry : frameInfo_) { - RkISP1FrameInfo *info = entry.second; - - pipe_->availableParamBuffers_.push(info->paramBuffer); - pipe_->availableStatBuffers_.push(info->statBuffer); - pipe_->availableMainPathBuffers_.push(info->mainPathBuffer); - - delete info; + for (const auto &[frame, info] : frameInfo_) { + pipe_->availableParamBuffers_.push(info.paramBuffer); + pipe_->availableStatBuffers_.push(info.statBuffer); + pipe_->availableMainPathBuffers_.push(info.mainPathBuffer); } frameInfo_.clear(); @@ -322,7 +318,7 @@ RkISP1FrameInfo *RkISP1Frames::find(unsigned int frame) auto itInfo = frameInfo_.find(frame); if (itInfo != frameInfo_.end()) - return itInfo->second; + return &itInfo->second; LOG(RkISP1, Fatal) << "Can't locate info from frame"; @@ -331,14 +327,12 @@ RkISP1FrameInfo *RkISP1Frames::find(unsigned int frame) RkISP1FrameInfo *RkISP1Frames::find(FrameBuffer *buffer) { - for (auto &itInfo : frameInfo_) { - RkISP1FrameInfo *info = itInfo.second; - - if (info->paramBuffer == buffer || - info->statBuffer == buffer || - info->mainPathBuffer == buffer || - info->selfPathBuffer == buffer) - return info; + for (auto &[frame, info] : frameInfo_) { + if (info.paramBuffer == buffer || + info.statBuffer == buffer || + info.mainPathBuffer == buffer || + info.selfPathBuffer == buffer) + return &info; } LOG(RkISP1, Fatal) << "Can't locate info from buffer"; @@ -348,11 +342,9 @@ RkISP1FrameInfo *RkISP1Frames::find(FrameBuffer *buffer) RkISP1FrameInfo *RkISP1Frames::find(Request *request) { - for (auto &itInfo : frameInfo_) { - RkISP1FrameInfo *info = itInfo.second; - - if (info->request == request) - return info; + for (auto &[frame, info] : frameInfo_) { + if (info.request == request) + return &info; } LOG(RkISP1, Fatal) << "Can't locate info from request";