diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader_status_bar.cpp b/cockatrice/src/interface/card_picture_loader/card_picture_loader_status_bar.cpp index fe699e61f..a731d067a 100644 --- a/cockatrice/src/interface/card_picture_loader/card_picture_loader_status_bar.cpp +++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader_status_bar.cpp @@ -63,21 +63,21 @@ void CardPictureLoaderStatusBar::addQueuedImageLoad(const QUrl &url, const Exact auto *entry = new CardPictureLoaderRequestStatusDisplayWidget(loadLog, url, card, setName); loadLog->addSettingsWidget(entry); logEntries.append(entry); - entriesByUrl[entry->getUrl()].append(entry); + entriesByUrl.insert(entry->getUrl(), entry); progressBar->setMaximum(progressBar->maximum() + 1); } void CardPictureLoaderStatusBar::addSuccessfulImageLoad(const QUrl &url) { - const auto entries = entriesByUrl.constFind(url.toString()); - if (entries == entriesByUrl.constEnd()) { + const QList entries = entriesByUrl.values(url.toString()); + if (entries.isEmpty()) { // The entry may already have been dropped from the log; the download // itself still succeeded, there is just nothing left to mark. return; } int finishedEntries = 0; - for (CardPictureLoaderRequestStatusDisplayWidget *statusDisplayWidget : entries.value()) { + for (CardPictureLoaderRequestStatusDisplayWidget *statusDisplayWidget : entries) { if (statusDisplayWidget->getFinished()) { continue; } @@ -116,16 +116,8 @@ void CardPictureLoaderStatusBar::removeLogEntry(CardPictureLoaderRequestStatusDi return; } - const QString entryUrl = entry->getUrl(); logEntries.removeOne(entry); - - auto entries = entriesByUrl.find(entryUrl); - if (entries != entriesByUrl.end()) { - entries.value().removeOne(entry); - if (entries.value().isEmpty()) { - entriesByUrl.erase(entries); - } - } + entriesByUrl.remove(entry->getUrl(), entry); // The progress bar's maximum counts the entries currently in the log and // its value the finished ones, so dropping an entry moves both counters back. diff --git a/cockatrice/src/interface/card_picture_loader/card_picture_loader_status_bar.h b/cockatrice/src/interface/card_picture_loader/card_picture_loader_status_bar.h index e5eb0f0d3..7f614e28f 100644 --- a/cockatrice/src/interface/card_picture_loader/card_picture_loader_status_bar.h +++ b/cockatrice/src/interface/card_picture_loader/card_picture_loader_status_bar.h @@ -1,8 +1,8 @@ #ifndef PICTURE_LOADER_STATUS_BAR_H #define PICTURE_LOADER_STATUS_BAR_H -#include #include +#include #include #include #include @@ -85,7 +85,9 @@ private: SettingsButtonWidget *loadLog; ///< Popup log showing individual request statuses QTimer *cleaner; ///< Timer for periodically cleaning old log entries QList logEntries; ///< Logged requests, oldest first - QHash> + // A URL can back several live entries: a request parked for a deferred retry is re-queued while + // its first entry is still pending, so a completion must finish every entry for that URL. + QMultiHash entriesByUrl; ///< Log entries indexed by their URL for O(1) completion lookup };