File indexing completed on 2024-04-28 15:39:55
0001 /* SPDX-FileCopyrightText: 2010-2018 Jesper Pedersen <blackie@blackie.dk> and 0002 Robert Krawitz <rlk@alum.mit.edu> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef FASTDIR_H 0008 #define FASTDIR_H 0009 0010 #include <kpabase/FileNameList.h> 0011 0012 #include <QSet> 0013 #include <QString> 0014 #include <QStringList> 0015 0016 namespace DB 0017 { 0018 /** 0019 FastDir is used in place of QDir because QDir stat()s every file in 0020 the directory, even if we tell it not to restrict anything. When 0021 scanning for new images, we don't want to look at files we already 0022 have in our database, and we also don't want to look at files whose 0023 names indicate that we don't care about them. So what we do is 0024 simply read the names from the directory and let the higher layers 0025 decide what to do with them. 0026 0027 On my sample database with ~20,000 images, this improves the time 0028 to rescan for images on a cold system from about 100 seconds to 0029 about 3 seconds. 0030 0031 -- Robert Krawitz, rlk@alum.mit.edu 2007-07-22 0032 */ 0033 typedef QSet<QString> StringSet; 0034 class FastDir 0035 { 0036 public: 0037 explicit FastDir(const QString &path); 0038 const QStringList entryList() const; 0039 QStringList sortFileList(const QStringList &files) const; 0040 QStringList sortFileList(const StringSet &files) const; 0041 0042 private: 0043 FastDir(); 0044 const QString m_path; 0045 QStringList m_sortedList; 0046 }; 0047 0048 bool sortByInode(const QByteArray &path); 0049 constexpr bool sortByName(const QByteArray &path); 0050 0051 } 0052 0053 #endif /* FASTDIR_H */ 0054 0055 // vi:expandtab:tabstop=4 shiftwidth=4: