Performance: Don't redundantly add the same exclude files #4967 (#4988)
authorckamm <mail@ckamm.de>
Mon, 20 Jun 2016 13:14:13 +0000 (15:14 +0200)
committerMarkus Goetz <markus@woboq.com>
Mon, 20 Jun 2016 13:14:13 +0000 (15:14 +0200)
Excludes: Don't redundantly add the same exclude files #4967, Never accept duplicate exclude patterns #4967

csync/src/csync_exclude.c
src/gui/folder.cpp
src/libsync/excludedfiles.cpp
src/libsync/excludedfiles.h

index fe999ed605ce88cd7da35e8ee46f0edf014f34f7..bad25f8d274780f400f422b8b83d8e097f294580 100644 (file)
 static
 #endif
 int _csync_exclude_add(c_strlist_t **inList, const char *string) {
+    size_t i = 0;
+
+    // We never want duplicates, so check whether the string is already
+    // in the list first.
+    if (*inList) {
+        for (i = 0; i < (*inList)->count; ++i) {
+            char *pattern = (*inList)->vector[i];
+            if (c_streq(pattern, string)) {
+                return 0;
+            }
+        }
+    }
     return c_strlist_add_grow(inList, string);
 }
 
index 0a88c68c9243509bd9c79f61afc9ca7be874afd8..66bc2584688052c39a30d94e4539663bc8a0d920 100644 (file)
@@ -695,6 +695,10 @@ void Folder::wipe()
 
 bool Folder::setIgnoredFiles()
 {
+    // Note: Doing this on each sync run and on Folder construction is
+    // unnecessary, because _engine->excludedFiles() persists between
+    // sync runs. This is not a big problem because ExcludedFiles maintains
+    // a QSet of files to load.
     ConfigFile cfg;
     QString systemList = cfg.excludeFile(ConfigFile::SystemScope);
     if( QFile::exists(systemList) ) {
index d4eed06d86b494d4463a77ae250ad265da999bdd..b2839d05da7c82a02e1d972873009928693ab7da 100644 (file)
@@ -42,7 +42,7 @@ ExcludedFiles& ExcludedFiles::instance()
 
 void ExcludedFiles::addExcludeFilePath(const QString& path)
 {
-    _excludeFiles.append(path);
+    _excludeFiles.insert(path);
 }
 
 bool ExcludedFiles::reloadExcludes()
index 5e47f7c2d863c7072b4136f26dda6f15f1a341ea..75895a396dd01b40cc38a14d13bf8e341eac7eaf 100644 (file)
@@ -16,7 +16,8 @@
 #include "owncloudlib.h"
 
 #include <QObject>
-#include <QStringList>
+#include <QSet>
+#include <QString>
 
 extern "C" {
 #include "std/c_string.h"
@@ -66,7 +67,7 @@ private:
     // This is a pointer to the csync exclude list, its is owned by this class
     // but the pointer can be in a csync_context so that it can itself also query the list.
     c_strlist_t** _excludesPtr;
-    QStringList _excludeFiles;
+    QSet<QString> _excludeFiles;
 };
 
 } // namespace OCC