Skip to content

Commit 1cd7646

Browse files
pobrnpinchartl
authored andcommitted
libcamera: framebuffer_allocator: Avoid double map lookup
Use `try_emplace()` on the map instead of `count()` and `operator[]` to avoid walking the tree twice. Signed-off-by: Barnabás Pőcze <[email protected]> Reviewed-by: Laurent Pinchart <[email protected]> Reviewed-by: Kieran Bingham <[email protected]> Signed-off-by: Laurent Pinchart <[email protected]>
1 parent b35f04b commit 1cd7646

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/libcamera/framebuffer_allocator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ FrameBufferAllocator::~FrameBufferAllocator()
8888
*/
8989
int FrameBufferAllocator::allocate(Stream *stream)
9090
{
91-
if (buffers_.count(stream)) {
91+
const auto &[it, inserted] = buffers_.try_emplace(stream);
92+
93+
if (!inserted) {
9294
LOG(Allocator, Error) << "Buffers already allocated for stream";
9395
return -EBUSY;
9496
}
9597

96-
int ret = camera_->exportFrameBuffers(stream, &buffers_[stream]);
98+
int ret = camera_->exportFrameBuffers(stream, &it->second);
9799
if (ret == -EINVAL)
98100
LOG(Allocator, Error)
99101
<< "Stream is not part of " << camera_->id()

0 commit comments

Comments
 (0)