File indexing completed on 2025-01-05 05:23:30

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "createstatisticjob.hpp"
0010 
0011 // Okteta core
0012 #include <Okteta/AbstractByteArrayModel>
0013 // Qt
0014 #include <QCoreApplication>
0015 
0016 namespace Kasten {
0017 
0018 static constexpr int StatisticBlockSize = 100000;
0019 
0020 int CreateStatisticJob::exec()
0021 {
0022     // reset
0023     memset(mByteCount, 0, 256 * sizeof(int));
0024 
0025     const Okteta::Address last = mByteArrayModel ? mSelection.end() : -1;
0026     Okteta::Address i = mByteArrayModel ? mSelection.start() : 0;
0027     Okteta::Address blockEnd = i;
0028     while (i <= last) {
0029         blockEnd += StatisticBlockSize;
0030         if (blockEnd > last) {
0031             blockEnd = last;
0032         }
0033 
0034         for (; i <= blockEnd; ++i) {
0035             ++mByteCount[mByteArrayModel->byte(i)];
0036         }
0037 
0038         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
0039     }
0040 
0041     deleteLater(); // TODO: could be reused on next search
0042 
0043     return (mByteArrayModel ? mSelection.width() : -1);
0044 }
0045 
0046 }
0047 
0048 #include "moc_createstatisticjob.cpp"