diff --git a/src/recurrence.cpp b/src/recurrence.cpp --- a/src/recurrence.cpp +++ b/src/recurrence.cpp @@ -1049,14 +1049,7 @@ } } sortAndRemoveDuplicates(extimes); - - int st = 0; - for (i = 0, end = extimes.count(); i < end; ++i) { - int j = times.removeSorted(extimes[i], st); - if (j >= 0) { - st = j; - } - } + inplaceSetDifference(times, extimes); return times; } @@ -1116,15 +1109,7 @@ } extimes += d->mExDateTimes; sortAndRemoveDuplicates(extimes); - - int st = 0; - for (i = 0, count = extimes.count(); i < count; ++i) { - int j = times.removeSorted(extimes[i], st); - if (j >= 0) { - st = j; - } - } - + inplaceSetDifference(times, extimes); return times; } diff --git a/src/recurrencehelper_p.h b/src/recurrencehelper_p.h --- a/src/recurrencehelper_p.h +++ b/src/recurrencehelper_p.h @@ -33,6 +33,18 @@ container.erase(std::unique(container.begin(), container.end())); } +template +inline void inplaceSetDifference(T &set1, const T &set2) +{ + auto beginIt = set1.begin(); + for (const auto &elem : set2) { + const auto it = std::lower_bound(beginIt, set1.end(), elem); + if (it != set1.end() && *it == elem) { + beginIt = set1.erase(it); + } + } +} + } #endif