From 07bbac352ff6470ae87f98ec2aa1d235552e7db5 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Sun, 27 Apr 2014 17:34:02 +0200 Subject: [PATCH] Do not construct a map inside a lessThan function lessThan functions have to be fast. Also Map -> Hash as we're not using order here. --- applets/systemtray/plugin/host.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/applets/systemtray/plugin/host.cpp b/applets/systemtray/plugin/host.cpp index eafd0b6e6..200fb0205 100644 --- a/applets/systemtray/plugin/host.cpp +++ b/applets/systemtray/plugin/host.cpp @@ -43,6 +43,7 @@ namespace SystemTray { +static QHash s_taskWeights; bool taskLessThan(const Task *lhs, const Task *rhs) { @@ -63,14 +64,15 @@ bool taskLessThan(const Task *lhs, const Task *rhs) } if (lhs->category() != rhs->category()) { - QMap weights; - weights.insert(Task::Communications, 0); - weights.insert(Task::SystemServices, 1); - weights.insert(Task::Hardware, 2); - weights.insert(Task::ApplicationStatus, 3); - weights.insert(Task::UnknownCategory, 4); - - return weights.value(lhs->category()) < weights.value(rhs->category()); + + if (s_taskWeights.isEmpty()) { + s_taskWeights.insert(Task::Communications, 0); + s_taskWeights.insert(Task::SystemServices, 1); + s_taskWeights.insert(Task::Hardware, 2); + s_taskWeights.insert(Task::ApplicationStatus, 3); + s_taskWeights.insert(Task::UnknownCategory, 4); + } + return s_taskWeights.value(lhs->category()) < s_taskWeights.value(rhs->category()); } return lhs->name() < rhs->name();