diff --git a/src/file/kinotify.cpp b/src/file/kinotify.cpp --- a/src/file/kinotify.cpp +++ b/src/file/kinotify.cpp @@ -19,7 +19,6 @@ */ #include "kinotify.h" -#include "optimizedbytearray.h" #include "fileindexerconfig.h" #include "filtereddiriterator.h" #include "baloodebug.h" @@ -90,10 +89,8 @@ bool userLimitReachedSignaled; // url <-> wd mappings - // Read the documentation fo OptimizedByteArray to understand why have a cache - QHash watchPathHash; - QHash pathWatchHash; - QSet pathCache; + QHash watchPathHash; + QHash pathWatchHash; Baloo::FileIndexerConfig* config; QStringList m_paths; @@ -125,13 +122,12 @@ // we always need the unmount event to maintain our path hash const int mask = newMode | newFlags | EventUnmount | FlagExclUnlink; - const QByteArray encpath = QFile::encodeName(path); + const QByteArray encpath = stripTrailingSlash(QFile::encodeName(path)); int wd = inotify_add_watch(inotify(), encpath.data(), mask); if (wd > 0) { // qCDebug(BALOO) << "Successfully added watch for" << path << watchPathHash.count(); - OptimizedByteArray normalized(stripTrailingSlash(encpath), pathCache); - watchPathHash.insert(wd, normalized); - pathWatchHash.insert(normalized, wd); + watchPathHash.insert(wd, encpath); + pathWatchHash.insert(encpath, wd); return true; } else { qCDebug(BALOO) << "Failed to create watch for" << path << strerror(errno); @@ -257,7 +253,7 @@ bool KInotify::watchingPath(const QString& path) const { const QByteArray p(stripTrailingSlash(QFile::encodeName(path))); - return d->pathWatchHash.contains(OptimizedByteArray(p, d->pathCache)); + return d->pathWatchHash.contains(p); } void KInotify::resetUserLimit() @@ -301,9 +297,9 @@ // Remove all the watches QByteArray encodedPath(QFile::encodeName(path)); - QHash::iterator it = d->watchPathHash.begin(); + auto it = d->watchPathHash.begin(); while (it != d->watchPathHash.end()) { - if (it.value().toByteArray().startsWith(encodedPath)) { + if (it.value().startsWith(encodedPath)) { inotify_rm_watch(d->inotify(), it.key()); d->pathWatchHash.remove(it.value()); it = d->watchPathHash.erase(it); @@ -361,11 +357,11 @@ // the event name only contains an interesting value if we get an event for a file/folder inside // a watched folder. Otherwise we should ignore it if (event->mask & (EventDeleteSelf | EventMoveSelf)) { - path = d->watchPathHash.value(event->wd).toByteArray(); + path = d->watchPathHash.value(event->wd); } else { // we cannot use event->len here since it contains the size of the buffer and not the length of the string const QByteArray eventName = QByteArray::fromRawData(event->name, qstrnlen(event->name, event->len)); - const QByteArray hashedPath = d->watchPathHash.value(event->wd).toByteArray(); + const QByteArray hashedPath = d->watchPathHash.value(event->wd); path = concatPath(hashedPath, eventName); } @@ -436,15 +432,13 @@ // update the path cache if (event->mask & IN_ISDIR) { - OptimizedByteArray optimOldPath(oldPath, d->pathCache); - QHash::iterator it = d->pathWatchHash.find(optimOldPath); + auto it = d->pathWatchHash.find(oldPath); if (it != d->pathWatchHash.end()) { // qCDebug(BALOO) << oldPath << path; const int wd = it.value(); - OptimizedByteArray optimPath(path, d->pathCache); - d->watchPathHash[wd] = optimPath; + d->watchPathHash[wd] = path; d->pathWatchHash.erase(it); - d->pathWatchHash.insert(optimPath, wd); + d->pathWatchHash.insert(path, wd); } } // qCDebug(BALOO) << oldPath << "EventMoveTo" << path; diff --git a/src/file/optimizedbytearray.h b/src/file/optimizedbytearray.h deleted file mode 100644 --- a/src/file/optimizedbytearray.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of the KDE Nepomuk Project - * Copyright (C) 2012 Vishesh Handa - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef OPTIMIZED_BYTE_ARRAY_H -#define OPTIMIZED_BYTE_ARRAY_H - -#include -#include -#include -#include - -/** - * This class holds a QByteArray which corresponds to a file url in a - * more memory efficient manner. - * - * It does so by splitting the url along the directory separator '/', and - * saving each path separately in a QVector. This is more memory efficient - * than storing it together cause it uses a QSet cache to lookup - * each part of the vector. This way, multiple OptimizedByteArrays share common - * parts of the url. This happens because Qt's containers are reference counted. - * - * \author Vishesh Handa - * - */ -class OptimizedByteArray -{ -public: - OptimizedByteArray() {} - - OptimizedByteArray(const QByteArray& array, QSet& cache) { - const QList list = array.split('/'); - QVector vec; - vec.reserve(list.size()); - for (const QByteArray& ba : list) { - if (!ba.isEmpty()) - vec << ba; - } - - m_data.reserve(vec.size()); - for (const QByteArray& arr : qAsConst(vec)) { - QSet< QByteArray >::iterator it = cache.find(arr); - if (it != cache.end()) - m_data.append(*it); - else - m_data.append(*cache.insert(arr)); - } - } - - QByteArray toByteArray() const { - int size = 0; - for (const QByteArray& arr : qAsConst(m_data)) - size += arr.size() + 1; - - QByteArray array; - array.reserve(size); - - for (const QByteArray& arr : qAsConst(m_data)) { - array.append('/'); - array.append(arr); - } - - return array; - } - - bool operator==(const OptimizedByteArray& other) const { - return m_data == other.m_data; - } - -private: - QVector m_data; -}; - -uint qHash(const OptimizedByteArray& arr) -{ - return qHash(arr.toByteArray()); -} - -Q_DECLARE_METATYPE(OptimizedByteArray) -Q_DECLARE_TYPEINFO(OptimizedByteArray, Q_MOVABLE_TYPE); - -#endif // OPTIMIZED_BYTE_ARRAY_H