From e30067518f58d60b834043027e598d9b85a128ef Mon Sep 17 00:00:00 2001 From: Aaron Seigo Date: Fri, 2 Nov 2012 13:46:55 +0100 Subject: [PATCH] required to lower memory consumption for PA4 --- runnercontext.cpp | 31 +++++++++++++++++++++++++++++++ runnercontext.h | 16 ++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/runnercontext.cpp b/runnercontext.cpp index 5d57540d9..abd6a4bc7 100644 --- a/runnercontext.cpp +++ b/runnercontext.cpp @@ -483,6 +483,37 @@ bool RunnerContext::removeMatch(const QString matchId) return true; } +bool RunnerContext::removeMatches(Plasma::AbstractRunner *runner) +{ + if (!isValid()) { + return false; + } + + QList presentMatchList; + + LOCK_FOR_READ(d) + foreach(const QueryMatch &match, d->matches) { + if (match.runner() == runner) { + presentMatchList << match; + } + } + UNLOCK(d) + + if (presentMatchList.isEmpty()) { + return false; + } + + LOCK_FOR_WRITE(d) + foreach (const QueryMatch &match, presentMatchList) { + d->matchesById.remove(match.id()); + d->matches.removeAll(match); + } + UNLOCK(d) + + emit d->q->matchesChanged(); + return true; +} + QList RunnerContext::matches() const { LOCK_FOR_READ(d) diff --git a/runnercontext.h b/runnercontext.h index 4bc7ee92b..741ac59c7 100644 --- a/runnercontext.h +++ b/runnercontext.h @@ -163,9 +163,9 @@ class PLASMA_EXPORT RunnerContext : public QObject * @param matchId the id of match to remove * * @return true if the match was removed, false otherwise. - * @since 4.4 + * @since 4.4 */ - bool removeMatch(const QString matchId); + bool removeMatch(const QString matchId); /** * Removes lists of matches from the existing list of matches. @@ -179,6 +179,18 @@ class PLASMA_EXPORT RunnerContext : public QObject */ bool removeMatches(const QStringList matchIdList); + /** + * Removes lists of matches from a given AbstractRunner + * + * This method is thread safe and causes the matchesChanged() signal to be emitted. + * + * @param runner the AbstractRunner from which to remove matches + * + * @return true if at least one match was removed, false otherwise. + * @since 4.10 + */ + bool removeMatches(AbstractRunner *runner); + /** * Retrieves all available matches for the current search term. *