cppcheck/test
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
..
cfg posix.cfg: Improved configuration for close(). Issue a warning in case close is called with a file pointer having a negative value. 2019-04-21 12:28:17 +02:00
cli Fix comment 2019-04-30 08:54:41 +02:00
synthetic
testsuites Typos found by running "codespell" (#1804) 2019-04-23 13:26:48 +02:00
CMakeLists.txt Add a check target to cmake (#1465) 2018-11-05 18:13:04 +01:00
options.cpp Allow multiple test case arguments to testrunner (#1755) 2019-03-26 20:28:40 +01:00
options.h Allow multiple test case arguments to testrunner (#1755) 2019-03-26 20:28:40 +01:00
redirect.h Updated copyright year 2018-01-14 15:37:52 +01:00
test.cxx
test64bit.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testassert.cpp Moved CheckAssert::assertWithSideEffects to normal checking 2019-03-09 16:50:50 +01:00
testastutils.cpp Adjust more test results for invalid code 2019-04-19 20:53:07 +02:00
testautovariables.cpp Fixed: FP return reference to thread_local variable (#1758) 2019-03-27 12:22:53 +01:00
testbool.cpp Use 'normal' checking instead of 'simplified' 2019-03-16 07:19:48 +01:00
testboost.cpp CheckBoost: Use 'normal' checking 2019-03-09 20:00:31 +01:00
testbufferoverrun.cpp Buffer overflow: Add CTU checking for pointer arithmetic overflows 2019-04-03 06:43:56 +02:00
testcharvar.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testclass.cpp Library: Added <smart-pointer> element 2019-04-24 13:06:58 +02:00
testcmdlineparser.cpp Fix compiler errors. After removing the -std=posix. 2019-04-12 10:41:53 +02:00
testcondition.cpp Use multiline in testing 2019-04-28 07:48:38 +02:00
testconstructors.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testcppcheck.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testerrorlogger.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testexceptionsafety.cpp Use 'normal' checking instead of 'simplified' 2019-03-16 07:19:48 +01:00
testfilelister.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testfiles.pri Fixed #8960 ("(debug) Unknown type 'x'." with alias in template class alias) (#1643) 2019-02-05 08:52:23 +01:00
testfunctions.cpp Fix false positive with ignoredReturnValue with std::move (#1809) 2019-04-26 12:22:31 +02:00
testgarbage.cpp Adjust some test results for invalid code. Comment out still crashing example for #8913 2019-04-19 17:42:21 +02:00
testimportproject.cpp astyle formatting 2019-04-16 19:07:44 +02:00
testincompletestatement.cpp Fix FP with unused variable (#1814) 2019-04-29 11:50:19 +02:00
testinternal.cpp CheckInternal: Extend redundant null pointer check before Token::Match() (#1789) 2019-04-06 07:44:44 +02:00
testio.cpp Fix #8992: Add originalTypeToken to auto (#1701) 2019-02-27 06:44:31 +01:00
testleakautovar.cpp CheckLeakAutoVar: Use Library::isSmartPointer() 2019-04-24 15:35:47 +02:00
testlibrary.cpp Library: Enhance minsize configuration and allow simple values. (#1736) 2019-03-17 14:22:26 +01:00
testmathlib.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testmemleak.cpp Fixed #8848 (False positive memory leak if locally defined type returns a new pointer) 2019-04-22 17:37:41 +02:00
testnullpointer.cpp Improve diagnostics with null smart pointers (#1805) 2019-04-26 11:30:09 +02:00
testoptions.cpp Allow multiple test case arguments to testrunner (#1755) 2019-03-26 20:28:40 +01:00
testother.cpp Fixed #9043 (false positive & regression: Variable '*s' is reassigned a value before the old one has been used.) 2019-04-16 19:07:26 +02:00
testpath.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testpathmatch.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testplatform.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testpostfixoperator.cpp Fixed #9042 (Another `using BOOL` type breach) (#1765) 2019-03-27 21:42:50 +01:00
testpreprocessor.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testrunner.cpp Add help to testrunner (#1704) 2019-03-02 08:06:23 +01:00
testrunner.vcxproj Fixed #8960 ("(debug) Unknown type 'x'." with alias in template class alias) (#1643) 2019-02-05 08:52:23 +01:00
testrunner.vcxproj.filters Export interfaces from cppcheck-core.dll used from testrunner. In turn remove ctu sources from testrunner which are obsolete now. 2018-12-28 23:09:44 +01:00
testsamples.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testsimplifytemplate.cpp partial fix for #8663 (Stack overflow with template disambiguator) (#1801) 2019-04-21 06:46:16 +02:00
testsimplifytokens.cpp simplifyMathExpression: Fix tests 2019-04-09 08:22:41 +02:00
testsimplifytypedef.cpp Fix issue 9006: False positive: Return value of function std::move() is not used. 2019-04-15 06:37:27 +02:00
testsimplifyusing.cpp Fixed #9042 (Another `using BOOL` type breach) (#1765) 2019-03-27 21:42:50 +01:00
testsizeof.cpp sizeof: write inconclusive warning if calculation in sizeof is done indirectly by macro 2019-02-26 21:06:44 +01:00
teststl.cpp STL: Better out of bounds checking for empty containers when index is unknown 2019-03-29 15:20:17 +01:00
teststring.cpp Checkstring fixes (#1783) 2019-04-06 06:54:38 +02:00
testsuite.cpp Allow multiple test case arguments to testrunner (#1755) 2019-03-26 20:28:40 +01:00
testsuite.h Add help to testrunner (#1704) 2019-03-02 08:06:23 +01:00
testsuppressions.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testsymboldatabase.cpp Fixed #8889 (varid on function when using trailing return type.) (#1800) 2019-04-18 20:22:39 +02:00
testthreadexecutor.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testtimer.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testtoken.cpp TestToken: Add more tests (#1806) 2019-04-25 07:08:13 +02:00
testtokenize.cpp Optimize astStringVerbose() for large arrays (#1815) 2019-04-30 13:35:48 +02:00
testtokenlist.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testtype.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testuninitvar.cpp Uninitialized variables: Fixed false positive 2019-03-09 11:30:45 +01:00
testunusedfunctions.cpp Fixed #8580 (False positive: unused function (lambda)) 2019-04-27 17:17:51 +02:00
testunusedprivfunc.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testunusedvar.cpp Update copyright year 2019-02-09 07:24:06 +01:00
testutils.h Update copyright year 2019-02-09 07:24:06 +01:00
testvaarg.cpp Disable all simplified checks 2019-03-16 09:17:50 +01:00
testvalueflow.cpp Implement #7597 - valueflow: global constant (#1802) 2019-04-21 06:54:32 +02:00
testvarid.cpp Fixed #8889 (varid on function when using trailing return type.) (#1800) 2019-04-18 20:22:39 +02:00