[clazy] [Bug 359305] false positives in container-anti-pattern

Sergio Martins via KDE Bugzilla bugzilla_noreply at kde.org
Fri Feb 12 10:57:25 GMT 2016


https://bugs.kde.org/show_bug.cgi?id=359305

--- Comment #1 from Sergio Martins <smartins at kde.org> ---
Your first example allocates once (due to keys() call), and it should allocate
0.
Use instead: for (auto it = someMap.cbegin(), end = someMap.cend(); it != end;
++it)

Your second example allocates twice (due to keys call) and it should allocate
once, construct the set manually instead.

This is what happens when you call keys():
template <class Key, class T>
Q_OUTOFLINE_TEMPLATE QList<Key> QHash<Key, T>::keys() const
{
    QList<Key> res;
    res.reserve(size());
    const_iterator i = begin();
    while (i != end()) {
        res.append(i.key());
        ++i;
    }
    return res;
}

You would be iterating twice instead of iterating the map directly.
I can update the README and make it more clear.

-- 
You are receiving this mail because:
You are the assignee for the bug.



More information about the Unassigned-bugs mailing list