Use QMutexLocker instead of manual lock/unlock calls.

Review Request #121306 - Created Dec. 1, 2014 and submitted

Milian Wolff
dvratil, vkrause
Just a minor cleanup patch, no change of behavior.

Use an QAtomicInt instead of a plain bool for Entity::cacheEnabled.

A plain bool is not thread safe and leads to undefined behavior.
So better be safe than sorry and use a thread safe QAtomicInt.

Optimize: Only do one hash lookup to retrieve value from cache.

Compilers do not merge the call to contains() and the successive
value() lookup. Using iterators thus saves us one QHash lookup.

Optimize: Skip value condition on invalid flags.

HandlerHelper::itemWithFlagsCount gets called quite often apparently
and I noticed that it was relatively slow from the Query Debugger
in Akonadi Console. EXPLAIN'ing the query showed that it was using
a slow-path for the WHERE FOO AND (BAR OR ASDF) condition. Here,
ASDF was always id = -1, the id of the $IGNORED flag, which
I apparently don't have. Getting rid of that condition simplifies
the query to WHERE FOO AND BAR, which is apparently much better
optimizable. Before, the query often showed a runtime of ~15ms.
Now it is down to ~9ms.

Milian Wolff
Daniel Vrátil
Milian Wolff
Review request changed

Status: Closed (submitted)