Use std::shared_ptrfor AlbumCoverLoaderResult

Reduces memory fragmentation with Qt 6
This commit is contained in:
Jonas Kvinge
2023-04-06 23:18:10 +02:00
parent 962536bc83
commit b660287779
38 changed files with 363 additions and 294 deletions

View File

@@ -23,6 +23,7 @@
#include <algorithm>
#include <cmath>
#include <memory>
#include <QObject>
#include <QCoreApplication>
@@ -256,7 +257,7 @@ void AlbumCoverFetcherSearch::AllProvidersFinished() {
// No results?
if (results_.isEmpty()) {
statistics_.missing_images_++;
emit AlbumCoverFetched(request_.id, AlbumCoverImageResult());
emit AlbumCoverFetched(request_.id, AlbumCoverImageResultPtr());
return;
}
@@ -332,7 +333,7 @@ void AlbumCoverFetcherSearch::ProviderCoverFetchFinished(QNetworkReply *reply) {
}
result.image_size = image.size();
result.score_quality = ScoreImage(image.size());
candidate_images_.insert(result.score(), CandidateImage(result, AlbumCoverImageResult(result.image_url, mime_type, image_data, image)));
candidate_images_.insert(result.score(), CandidateImage(result, std::make_shared<AlbumCoverImageResult>(result.image_url, mime_type, image_data, image)));
qLog(Debug) << reply->url() << "from" << result.provider << "scored" << result.score();
}
else {
@@ -380,7 +381,7 @@ float AlbumCoverFetcherSearch::ScoreImage(const QSize size) {
void AlbumCoverFetcherSearch::SendBestImage() {
AlbumCoverImageResult result;
AlbumCoverImageResultPtr result = std::make_shared<AlbumCoverImageResult>();
if (!candidate_images_.isEmpty()) {
QList<CandidateImage> candidate_images = candidate_images_.values();
@@ -391,8 +392,8 @@ void AlbumCoverFetcherSearch::SendBestImage() {
statistics_.chosen_images_by_provider_[best_image.result.provider]++;
statistics_.chosen_images_++;
statistics_.chosen_width_ += result.image.width();
statistics_.chosen_height_ += result.image.height();
statistics_.chosen_width_ += result->image.width();
statistics_.chosen_height_ += result->image.height();
}
else {
statistics_.missing_images_++;