diff options
author | Barnabás Pőcze <pobrn@protonmail.com> | 2022-11-26 23:42:27 +0000 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2022-11-28 16:11:20 +0200 |
commit | 1cd7646f970d90f3c8bec02259a2415c5cf89016 (patch) | |
tree | 6e7187b349021cdddf2dfa1ef334dfb60298e8ec | |
parent | b35f04b3c19487de903b67340fcfb801557295d3 (diff) |
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 <pobrn@protonmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
-rw-r--r-- | src/libcamera/framebuffer_allocator.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libcamera/framebuffer_allocator.cpp b/src/libcamera/framebuffer_allocator.cpp index 4df27cac..dabd9219 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() |