cppcheck/lib
Rikard Falkeborn c7d7f8738c Optimize astStringVerbose() for large arrays (#1815)
Change the astStringVerbose() recursion to extend a string instead of
returning one. This has the benefit that for tokens where the recursion
runs deep (typically large arrays), the time savings can be substantial
(see comments on benchmarks further down).

The reason is that previously, for each token, the astString of its
operands was constructed, and then appended to this tokens astString.
This led to a lot of unnecessary string copying (and with that
allocations). Instead, by passing the string by reference, the number
of temporary strings is greatly reduced.

Another way of seeing it is that previously, the string was constructed
from end to beginning, but now it is constructed from the beginning to
end. There was no notable speedup by preallocating the entire string
using string::reserve() (at least not on Linux).

To benchmark, the changes and master were tested on Linux using the
commands:

	make
	time cppcheck --debug --verbose $file >/dev/null

i.e., the cppcheck binary was compiled with the settings in the
Makefile. Printing the output to screen or file will of course take
longer time.

In Trac ticket #8355 which triggered this change, an example file from the
Wine repository was attached. Running the above cppcheck on master took
24 minutes and with the changes in this commmit, took 22 seconds.

Another test made was on lib/tokenlist.cpp in the cppcheck repo, which is
more "normal" file. On that file there was no measurable time difference.

A synthetic benchmark was generated to illustrate the effects on dumping
the ast for arrays of different sizes. The generate code looked as
follows:

	const int array[] = {...};

with different number of elements. The results are as follows (times are
in seconds):

	N	master optimized
	10	0.1    0.1
	100	0.1    0.1
	1000	2.8    0.7
	2000	19     1.8
	3000	53     3.8
	5000	350    10
	10000	3215   38

As we can see, for small arrays, there is no time difference, but for
large arrays the time savings are substantial.
2019-04-30 13:35:48 +02:00
..
CMakeLists.txt CMake: Find header in externals, e.g. externals/picojson.h 2019-04-22 18:52:02 +02:00
analyzerinfo.cpp Buffer overflow: Add CTU checking for pointer arithmetic overflows 2019-04-03 06:43:56 +02:00
analyzerinfo.h Updated copyright year 2018-10-13 18:20:31 +02:00
astutils.cpp Refactoring: Use stl algorithm 2019-04-28 07:40:00 +02:00
astutils.h Fix issue 9006: False positive: Return value of function std::move() is not used. 2019-04-15 06:37:27 +02:00
check.cpp Updated copyright year 2018-10-13 18:20:31 +02:00
check.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
check64bit.cpp
check64bit.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkassert.cpp Update copyright year 2019-02-09 07:24:06 +01:00
checkassert.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkautovariables.cpp Fix issue 8996: False positive duplicateCondition 2019-03-19 06:25:10 +01:00
checkautovariables.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkbool.cpp Rewrite CheckBool::checkAssignBoolToPointer to use ValueType 2019-03-09 19:15:06 +01:00
checkbool.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkboost.cpp
checkboost.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkbufferoverrun.cpp Modernizing; Use std::accumulate instead of for loop 2019-04-28 11:25:43 +02:00
checkbufferoverrun.h Buffer overflow: Add CTU checking for pointer arithmetic overflows 2019-04-03 06:43:56 +02:00
checkclass.cpp Library: Added <smart-pointer> element 2019-04-24 13:06:58 +02:00
checkclass.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkcondition.cpp Fix issue 9103: False positive duplicateConditionAssign (#1808) 2019-04-26 12:30:41 +02:00
checkcondition.h astyle formatting 2019-04-18 20:21:00 +02:00
checkexceptionsafety.cpp
checkexceptionsafety.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkfunctions.cpp Fix false positive with ignoredReturnValue with std::move (#1809) 2019-04-26 12:22:31 +02:00
checkfunctions.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkinternal.cpp CheckInternal: Extend redundant null pointer check before Token::Match() (#1789) 2019-04-06 07:44:44 +02:00
checkinternal.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkio.cpp Update copyright year 2019-02-09 07:24:06 +01:00
checkio.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkleakautovar.cpp CheckLeakAutoVar: Use Library::isSmartPointer() 2019-04-24 15:35:47 +02:00
checkleakautovar.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkmemoryleak.cpp Fixed #8848 (False positive memory leak if locally defined type returns a new pointer) 2019-04-22 17:37:41 +02:00
checkmemoryleak.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checknullpointer.cpp Improve diagnostics with null smart pointers (#1805) 2019-04-26 11:30:09 +02:00
checknullpointer.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkother.cpp Removed --std=posix. From now on, if you use --library=posix then the posix checks will be enabled. 2019-04-12 06:47:28 +02:00
checkother.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkpostfixoperator.cpp
checkpostfixoperator.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checksizeof.cpp sizeof: write inconclusive warning if calculation in sizeof is done indirectly by macro 2019-02-26 21:06:44 +01:00
checksizeof.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkstl.cpp STL: Better out of bounds checking for empty containers when index is unknown 2019-03-29 15:20:17 +01:00
checkstl.h Clarify STL out of bounds warning message 2019-03-29 11:13:25 +01:00
checkstring.cpp Checkstring fixes (#1783) 2019-04-06 06:54:38 +02:00
checkstring.h Checkstring fixes (#1783) 2019-04-06 06:54:38 +02:00
checktype.cpp Update copyright year 2019-02-09 07:24:06 +01:00
checktype.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkuninitvar.cpp CheckBufferOverrun: Add CTU analysis 2019-03-23 08:36:10 +01:00
checkuninitvar.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkunusedfunctions.cpp Fixed #8580 (False positive: unused function (lambda)) 2019-04-27 17:17:51 +02:00
checkunusedfunctions.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkunusedvar.cpp Unused struct member: Fix FPs seen in daca@home results for template structs 2019-03-06 20:51:48 +01:00
checkunusedvar.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
checkvaarg.cpp Update copyright year 2019-02-09 07:24:06 +01:00
checkvaarg.h Disable all simplified checks 2019-03-16 09:17:50 +01:00
config.h Travis: Enable missingOverride checker 2019-01-13 12:21:01 +01:00
cppcheck.cpp Refactoring; Use const reference instead of const 2019-04-29 08:53:36 +02:00
cppcheck.h test/cli: execute addon 2019-04-14 15:00:03 +02:00
cppcheck.natvis
cppcheck.vcxproj Add ctu sources to VS projects 2018-12-27 22:11:40 +01:00
cppcheck.vcxproj.filters Add ctu sources to VS projects 2018-12-27 22:11:40 +01:00
ctu.cpp CheckBufferOverrun: Better CTU checking when variable address is passed 2019-03-23 15:57:17 +01:00
ctu.h CheckBufferOverrun: Add CTU analysis 2019-03-23 08:36:10 +01:00
errorlogger.cpp Add missing line feed to the generated plist output (#1792) 2019-04-08 18:09:18 +02:00
errorlogger.h Update copyright year 2019-02-09 07:24:06 +01:00
importproject.cpp dmake: use -isystem for externals to avoid compiler warnings 2019-04-19 14:52:49 +02:00
importproject.h analyzing one vs config (first debug config that matches platform) 2019-04-13 20:01:40 +02:00
lib.pri CTU: Refactoring 2018-12-25 21:11:23 +01:00
library.cpp Library: Added <smart-pointer> element 2019-04-24 13:06:58 +02:00
library.h Library: Added <smart-pointer> element 2019-04-24 13:06:58 +02:00
matchcompiler.h
mathlib.cpp Update copyright year 2019-02-09 07:24:06 +01:00
mathlib.h Update copyright year 2019-02-09 07:24:06 +01:00
path.cpp Update copyright year 2019-02-09 07:24:06 +01:00
path.h Update copyright year 2019-02-09 07:24:06 +01:00
pathmatch.cpp Updated copyright year 2018-10-13 18:20:31 +02:00
pathmatch.h Updated copyright year 2018-10-13 18:20:31 +02:00
pcrerules.pri
platform.cpp
platform.h Fix Cppcheck error message 2018-10-20 15:28:34 +02:00
preprocessor.cpp Optimization: Library does not need to store "#define " substring for each define 2019-02-28 22:34:26 +01:00
preprocessor.h
settings.cpp Refactoring; Reorder Settings members alphabetically. 2019-04-13 15:34:50 +02:00
settings.h test/cli: execute addon 2019-04-14 15:00:03 +02:00
standards.h Add -std=c++17 and allow semicolon in 'if ()' 2019-04-12 09:10:25 +02:00
suppressions.cpp Update copyright year 2019-02-09 07:24:06 +01:00
suppressions.h
symboldatabase.cpp Improve diagnostics with null smart pointers (#1805) 2019-04-26 11:30:09 +02:00
symboldatabase.h Improve diagnostics with null smart pointers (#1805) 2019-04-26 11:30:09 +02:00
templatesimplifier.cpp partial fix for #8663 (Stack overflow with template disambiguator) (#1801) 2019-04-21 06:46:16 +02:00
templatesimplifier.h Fixed #9040 (Type alias 'BOOL' declared with 'using' keyword breaks type detection) (#1759) 2019-03-26 07:09:56 +01:00
timer.cpp
timer.h Update copyright year 2019-02-09 07:24:06 +01:00
token.cpp Optimize astStringVerbose() for large arrays (#1815) 2019-04-30 13:35:48 +02:00
token.h Optimize astStringVerbose() for large arrays (#1815) 2019-04-30 13:35:48 +02:00
tokenize.cpp Fixed #9110 (Syntax error on valid C++ code) (#1813) 2019-04-29 15:17:37 +02:00
tokenize.h Fix Cppcheck passedByValue warning 2019-04-28 07:58:47 +02:00
tokenlist.cpp Fix FP with unused variable (#1814) 2019-04-29 11:50:19 +02:00
tokenlist.h Run simplifyPlatformTypes on library return types (#1672) 2019-02-15 13:29:52 +01:00
utils.h
valueflow.cpp astyle formatting 2019-04-26 11:30:35 +02:00
valueflow.h Array index: Checking array index out of bounds for dynamic buffers 2019-03-17 13:09:15 +01:00
version.h Set version to 1.87.99/1.88 dev 2019-02-27 21:30:54 +01:00
version.rc