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>
This commit is contained in:
committed by
Laurent Pinchart
parent
b35f04b3c1
commit
1cd7646f97
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user