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
This commit is contained in:
parent
abcff79a15
commit
57eff6cf9d
2 changed files with 23 additions and 37 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue