Cherrypicked pull request #1743 (cppcheck performance fixes).