From 43a2aec92be2a4a966112938ec39f51ffe1a7b23 Mon Sep 17 00:00:00 2001 From: ckamm Date: Mon, 20 Jun 2016 15:14:13 +0200 Subject: [PATCH] Performance: Don't redundantly add the same exclude files #4967 (#4988) Excludes: Don't redundantly add the same exclude files #4967, Never accept duplicate exclude patterns #4967 --- csync/src/csync_exclude.c | 12 ++++++++++++ src/gui/folder.cpp | 4 ++++ src/libsync/excludedfiles.cpp | 2 +- src/libsync/excludedfiles.h | 5 +++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/csync/src/csync_exclude.c b/csync/src/csync_exclude.c index fe999ed60..bad25f8d2 100644 --- a/csync/src/csync_exclude.c +++ b/csync/src/csync_exclude.c @@ -44,6 +44,18 @@ 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); } diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 0a88c68c9..66bc25846 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -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) ) { diff --git a/src/libsync/excludedfiles.cpp b/src/libsync/excludedfiles.cpp index d4eed06d8..b2839d05d 100644 --- a/src/libsync/excludedfiles.cpp +++ b/src/libsync/excludedfiles.cpp @@ -42,7 +42,7 @@ ExcludedFiles& ExcludedFiles::instance() void ExcludedFiles::addExcludeFilePath(const QString& path) { - _excludeFiles.append(path); + _excludeFiles.insert(path); } bool ExcludedFiles::reloadExcludes() diff --git a/src/libsync/excludedfiles.h b/src/libsync/excludedfiles.h index 5e47f7c2d..75895a396 100644 --- a/src/libsync/excludedfiles.h +++ b/src/libsync/excludedfiles.h @@ -16,7 +16,8 @@ #include "owncloudlib.h" #include -#include +#include +#include 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 _excludeFiles; }; } // namespace OCC -- 2.30.2