File indexing completed on 2025-01-19 03:55:48

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-01-18
0007  * Description : item info task splitter
0008  *
0009  * SPDX-FileCopyrightText: 2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 // Local includes
0016 
0017 #include "iteminfotasksplitter.h"
0018 #include "parallelworkers.h"
0019 
0020 namespace Digikam
0021 {
0022 
0023 ItemInfoTaskSplitter::ItemInfoTaskSplitter(const FileActionItemInfoList& list)
0024     : FileActionItemInfoList(list)
0025 {
0026     int parts = ParallelWorkers::optimalWorkerCount();
0027     m_n       = qMax(1, list.size() / parts);
0028 }
0029 
0030 ItemInfoTaskSplitter::~ItemInfoTaskSplitter()
0031 {
0032 }
0033 
0034 FileActionItemInfoList ItemInfoTaskSplitter::next()
0035 {
0036     QList<ItemInfo> list;
0037 
0038     if (size() <= m_n)
0039     {
0040         list = *this;
0041         clear();
0042     }
0043     else
0044     {
0045         list.reserve(m_n);
0046 
0047         // qCopy does not work with QList
0048         for (int i = 0 ;  i < m_n ; ++i)
0049         {
0050             list << at(i);
0051         }
0052 
0053         erase(begin(), begin() + m_n);
0054     }
0055 
0056     return FileActionItemInfoList::continueTask(list, progress());
0057 }
0058 
0059 bool ItemInfoTaskSplitter::hasNext() const
0060 {
0061     return !isEmpty();
0062 }
0063 
0064 } // namespace Digikam