summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2013-01-08 17:23:58 +0100
committerStephan Bergmann <sbergman@redhat.com>2013-01-08 17:30:34 +0100
commit57eff6cf9db5d765482a2c41698915c37927ae57 (patch)
treea1d9cfc0bdcf1674d1d78357859fde1db2907317 /desktop
parentabcff79a15e39add5f89512984980ee0f3821b68 (diff)
Fix MigrationImpl::subtract
"The original code is broken to begin with, as it ignores the return values from the std::unique calls, so excess elements remain at the end of va and vb." (<http://lists.freedesktop.org/archives/libreoffice/2013-January/043552.html> "[PATCH] Simplify MigrationImpl::subtract in desktop;" see that mail thread also for the inspiration to use std::set_difference.) This fix is not very relevant though, as there are no "ExcludedFiles" lists in officecfg/registry/data/org/openoffice/Setup.xcu, so the second argument is always empty, so the return value is always a (sorted) copy of the first argument, and the "IncludedFiles" lists in Setup.xcu produce no duplicates, so std::unique does not shrink the first argument anyway. Change-Id: Ie9fb64ee40fef6e7bdf0f5d0eca5717fec7b0d50
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/migration/migration.cxx59
-rw-r--r--desktop/source/migration/migration_impl.hxx1
2 files changed, 23 insertions, 37 deletions
diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx
index d4edf4f826f0..82f573f15c10 100644
--- a/desktop/source/migration/migration.cxx
+++ b/desktop/source/migration/migration.cxx
@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include "sal/config.h"
+#include <algorithm>
#include <map>
#include <new>
#include <set>
@@ -700,6 +702,25 @@ strings_vr MigrationImpl::getAllFiles(const OUString& baseURL) const
return vrResult;
}
+namespace {
+
+// removes elements of vector 2 in vector 1
+strings_v subtract(strings_v const & va, strings_v const & vb) {
+ strings_v a(va);
+ std::sort(a.begin(), a.end());
+ strings_v::iterator ae(std::unique(a.begin(), a.end()));
+ strings_v b(vb);
+ std::sort(b.begin(), b.end());
+ strings_v::iterator be(std::unique(b.begin(), b.end()));
+ strings_v c(ae - a.begin());
+ strings_v::iterator ce(
+ std::set_difference(a.begin(), ae, b.begin(), be, c.begin()));
+ c.resize(ce - c.begin());
+ return c;
+}
+
+}
+
strings_vr MigrationImpl::compileFileList()
{
@@ -716,8 +737,8 @@ strings_vr MigrationImpl::compileFileList()
{
vrInclude = applyPatterns(*vrFiles, i_migr->includeFiles);
vrExclude = applyPatterns(*vrFiles, i_migr->excludeFiles);
- subtract(*vrInclude, *vrExclude);
- vrResult->insert(vrResult->end(), vrInclude->begin(), vrInclude->end());
+ strings_v sub(subtract(*vrInclude, *vrExclude));
+ vrResult->insert(vrResult->end(), sub.begin(), sub.end());
++i_migr;
}
return vrResult;
@@ -842,40 +863,6 @@ void MigrationImpl::copyConfig() {
}
}
-// removes elements of vector 2 in vector 1
-void MigrationImpl::subtract(strings_v& va, const strings_v& vb_c) const
-{
- strings_v vb(vb_c);
- // ensure uniqueness of entries
- sort(va.begin(), va.end());
- sort(vb.begin(), vb.end());
- unique(va.begin(), va.end());
- unique(vb.begin(), vb.end());
-
- strings_v::const_iterator i_ex = vb.begin();
- strings_v::iterator i_in;
- strings_v::iterator i_next;
- while (i_ex != vb.end())
- {
- i_in = va.begin();
- while (i_in != va.end())
- {
- if ( *i_in == *i_ex)
- {
- i_next = i_in+1;
- va.erase(i_in);
- i_in = i_next;
- // we can only find one match since we
- // ensured uniquness of the entries. ergo:
- break;
- }
- else
- ++i_in;
- }
- ++i_ex;
- }
-}
-
uno::Reference< XNameAccess > MigrationImpl::getConfigAccess(const sal_Char* pPath, sal_Bool bUpdate)
{
uno::Reference< XNameAccess > xNameAccess;
diff --git a/desktop/source/migration/migration_impl.hxx b/desktop/source/migration/migration_impl.hxx
index 5458f8cd907f..ef2e659954fc 100644
--- a/desktop/source/migration/migration_impl.hxx
+++ b/desktop/source/migration/migration_impl.hxx
@@ -208,7 +208,6 @@ private:
strings_vr compileFileList();
// helpers
- void subtract(strings_v& va, const strings_v& vb_c) const;
strings_vr getAllFiles(const rtl::OUString& baseURL) const;
strings_vr applyPatterns(const strings_v& vSet, const strings_v& vPatterns) const;
NS_UNO::Reference< NS_CSS::container::XNameAccess > getConfigAccess(const sal_Char* path, sal_Bool rw=sal_False);