From 78ec753a3c72984568281f468e207e7577a772be Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 19 Apr 2022 17:14:50 -0300 Subject: [PATCH] Simplify list of workers in ThumbnailGenerator with unique_ptrs --- src/app/thumbnail_generator.cpp | 12 ++++-------- src/app/thumbnail_generator.h | 5 +++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/app/thumbnail_generator.cpp b/src/app/thumbnail_generator.cpp index ded732746..b3446f83e 100644 --- a/src/app/thumbnail_generator.cpp +++ b/src/app/thumbnail_generator.cpp @@ -250,10 +250,8 @@ bool ThumbnailGenerator::checkWorkers() for (WorkerList::iterator it=m_workers.begin(); it != m_workers.end(); ) { - Worker* worker = *it; - worker->updateProgress(); - if (worker->isDone()) { - delete worker; + (*it)->updateProgress(); + if ((*it)->isDone()) { it = m_workers.erase(it); } else { @@ -334,7 +332,7 @@ void ThumbnailGenerator::stopAllWorkers() } base::scoped_lock hold(m_workersAccess); - for (auto worker : m_workers) + for (const auto& worker : m_workers) worker->stop(); } @@ -342,9 +340,7 @@ void ThumbnailGenerator::startWorker() { base::scoped_lock hold(m_workersAccess); if (m_workers.size() < m_maxWorkers) { - std::unique_ptr worker(new Worker(m_remainingItems)); - m_workers.push_back(worker.get()); - worker.release(); + m_workers.push_back(std::make_unique(m_remainingItems)); } } diff --git a/src/app/thumbnail_generator.h b/src/app/thumbnail_generator.h index cd6911dd5..e7ec3c80f 100644 --- a/src/app/thumbnail_generator.h +++ b/src/app/thumbnail_generator.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019 Igara Studio S.A. +// Copyright (C) 2019-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -47,7 +47,8 @@ namespace app { void startWorker(); class Worker; - typedef std::vector WorkerList; + using WorkerPtr = std::unique_ptr; + using WorkerList = std::vector; struct Item { IFileItem* fileitem;