[Libreoffice-commits] .: desktop/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Jan 8 08:30:54 PST 2013


 desktop/source/migration/migration.cxx      |   59 ++++++++++------------------
 desktop/source/migration/migration_impl.hxx |    1 
 2 files changed, 23 insertions(+), 37 deletions(-)

New commits:
commit 57eff6cf9db5d765482a2c41698915c37927ae57
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Jan 8 17:23:58 2013 +0100

    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

diff --git a/desktop/source/migration/migration.cxx b/desktop/source/migration/migration.cxx
index d4edf4f..82f573f 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 5458f8c..ef2e659 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);


More information about the Libreoffice-commits mailing list