Message ID | 20250310170335.185297-1-barnabas.pocze@ideasonboard.com |
---|---|
State | New |
Headers | show |
Series |
|
Related | show |
Quoting Barnabás Pőcze (2025-03-10 17:03:35) > Simplify a bit by storing the `EventNotifier` objects directly in the > `std::map` instead of wrapping them in unique_ptr. An other advantage > is that it removes one allocation per fence. This one sounds good, and doesn't impact public API/ABI as far as I can tell: Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> > --- > include/libcamera/internal/request.h | 2 +- > src/libcamera/request.cpp | 13 +++++-------- > 2 files changed, 6 insertions(+), 9 deletions(-) > > diff --git a/include/libcamera/internal/request.h b/include/libcamera/internal/request.h > index 73e9bb5cc..78cb99f36 100644 > --- a/include/libcamera/internal/request.h > +++ b/include/libcamera/internal/request.h > @@ -59,7 +59,7 @@ private: > bool prepared_ = false; > > std::unordered_set<FrameBuffer *> pending_; > - std::map<FrameBuffer *, std::unique_ptr<EventNotifier>> notifiers_; > + std::map<FrameBuffer *, EventNotifier> notifiers_; > std::unique_ptr<Timer> timer_; > }; > > diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp > index b206ac132..6fa1801a0 100644 > --- a/src/libcamera/request.cpp > +++ b/src/libcamera/request.cpp > @@ -228,15 +228,12 @@ void Request::Private::prepare(std::chrono::milliseconds timeout) > if (!fence) > continue; > > - std::unique_ptr<EventNotifier> notifier = > - std::make_unique<EventNotifier>(fence->fd().get(), > - EventNotifier::Read); > + auto [it, inserted] = notifiers_.try_emplace(buffer, fence->fd().get(), EventNotifier::Type::Read); > + ASSERT(inserted); > > - notifier->activated.connect(this, [this, buffer] { > - notifierActivated(buffer); > - }); > - > - notifiers_[buffer] = std::move(notifier); > + it->second.activated.connect(this, [this, buffer] { > + notifierActivated(buffer); > + }); > } > > if (notifiers_.empty()) { > -- > 2.48.1 >
diff --git a/include/libcamera/internal/request.h b/include/libcamera/internal/request.h index 73e9bb5cc..78cb99f36 100644 --- a/include/libcamera/internal/request.h +++ b/include/libcamera/internal/request.h @@ -59,7 +59,7 @@ private: bool prepared_ = false; std::unordered_set<FrameBuffer *> pending_; - std::map<FrameBuffer *, std::unique_ptr<EventNotifier>> notifiers_; + std::map<FrameBuffer *, EventNotifier> notifiers_; std::unique_ptr<Timer> timer_; }; diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index b206ac132..6fa1801a0 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -228,15 +228,12 @@ void Request::Private::prepare(std::chrono::milliseconds timeout) if (!fence) continue; - std::unique_ptr<EventNotifier> notifier = - std::make_unique<EventNotifier>(fence->fd().get(), - EventNotifier::Read); + auto [it, inserted] = notifiers_.try_emplace(buffer, fence->fd().get(), EventNotifier::Type::Read); + ASSERT(inserted); - notifier->activated.connect(this, [this, buffer] { - notifierActivated(buffer); - }); - - notifiers_[buffer] = std::move(notifier); + it->second.activated.connect(this, [this, buffer] { + notifierActivated(buffer); + }); } if (notifiers_.empty()) {
Simplify a bit by storing the `EventNotifier` objects directly in the `std::map` instead of wrapping them in unique_ptr. An other advantage is that it removes one allocation per fence. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- include/libcamera/internal/request.h | 2 +- src/libcamera/request.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-)