From 0a8fef1f516a2d230c34980b31d8e46d891941e1 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 7 Jan 2016 21:35:14 -0800 Subject: [PATCH] [core] Merge OnlineFileRequestImpl::notify into OnlineFileRequestImpl::setResponse In every case where setResponse is called, notify was called soon after. In one case immediately, in another, after intervening functions which are safe to reorder after notifications. The null-check of response is safe to eliminate because response must not be null inside setResponse. --- platform/default/online_file_source.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/platform/default/online_file_source.cpp b/platform/default/online_file_source.cpp index 4d9a13bd8..970929c1e 100644 --- a/platform/default/online_file_source.cpp +++ b/platform/default/online_file_source.cpp @@ -62,8 +62,10 @@ public: void removeObserver(FileRequest*); bool hasObservers() const; - // Updates/gets the response of this request object. + // Set the response of this request object and notify all observers. void setResponse(const std::shared_ptr&); + + // Get the response of this request object. const std::shared_ptr& getResponse() const; // Returns the seconds we have to wait until we need to redo this request. A value of 0 @@ -75,10 +77,6 @@ public: // stale flag set, if the response is expired. void checkResponseFreshness(); - // Notifies all observers. - void notify(); - - private: // Stores a set of all observing Request objects. std::unordered_map observers; @@ -258,9 +256,6 @@ void OnlineFileSource::Impl::startCacheRequest(OnlineFileRequestImpl& request) { startRealRequest(request); } - // Notify in all cases; requestors can decide whether they want to use stale responses. - request.notify(); - reschedule(request); }); } @@ -290,7 +285,6 @@ void OnlineFileSource::Impl::startRealRequest(OnlineFileRequestImpl& request) { } request.setResponse(response); - request.notify(); reschedule(request); }; @@ -364,14 +358,6 @@ bool OnlineFileRequestImpl::hasObservers() const { return !observers.empty(); } -void OnlineFileRequestImpl::notify() { - if (response) { - for (auto& req : observers) { - req.second(*response); - } - } -} - void OnlineFileRequestImpl::setResponse(const std::shared_ptr& response_) { response = response_; @@ -381,6 +367,11 @@ void OnlineFileRequestImpl::setResponse(const std::shared_ptr& r // Reset the number of subsequent failed requests after we got a successful one. failedRequests = 0; } + + // Notify in all cases; requestors can decide whether they want to use stale responses. + for (auto& req : observers) { + req.second(*response); + } } const std::shared_ptr& OnlineFileRequestImpl::getResponse() const {