Skip to content

Commit 9910c1f

Browse files
dinkoladanmar
authored andcommitted
Fixed cppcheck-opensource#6617 (preprocessor performance improvement)
1 parent 8ffa917 commit 9910c1f

8 files changed

Lines changed: 321 additions & 306 deletions

File tree

lib/cppcheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ unsigned int CppCheck::processFile(const std::string& filename, std::istream& fi
154154

155155
bool internalErrorFound(false);
156156
try {
157-
Preprocessor preprocessor(&_settings, this);
157+
Preprocessor preprocessor(_settings, this);
158158
std::list<std::string> configurations;
159159
std::string filedata;
160160

@@ -289,7 +289,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg
289289
void CppCheck::analyseFile(std::istream &fin, const std::string &filename)
290290
{
291291
// Preprocess file..
292-
Preprocessor preprocessor(&_settings, this);
292+
Preprocessor preprocessor(_settings, this);
293293
std::list<std::string> configurations;
294294
std::string filedata;
295295
preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths);

lib/preprocessor.cpp

Lines changed: 114 additions & 126 deletions
Large diffs are not rendered by default.

lib/preprocessor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CPPCHECKLIB Preprocessor {
5454
/** character that is inserted in expanded macros */
5555
static char macroChar;
5656

57-
Preprocessor(Settings *settings = nullptr, ErrorLogger *errorLogger = nullptr);
57+
Preprocessor(Settings& settings, ErrorLogger *errorLogger = nullptr);
5858

5959
static bool missingIncludeFlag;
6060
static bool missingSystemIncludeFlag;
@@ -268,7 +268,7 @@ class CPPCHECKLIB Preprocessor {
268268
*/
269269
void handleIncludes(std::string &code, const std::string &filePath, const std::list<std::string> &includePaths);
270270

271-
Settings *_settings;
271+
Settings& _settings;
272272
ErrorLogger *_errorLogger;
273273

274274
/** filename for cpp/c file - useful when reporting errors */

test/testmemleak.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6453,7 +6453,7 @@ class TestMemleakGLib : public TestFixture {
64536453
errout.str("");
64546454

64556455
// Preprocess...
6456-
Preprocessor preprocessor(&settings, this);
6456+
Preprocessor preprocessor(settings, this);
64576457
std::istringstream istrpreproc(code);
64586458
std::map<std::string, std::string> actual;
64596459
preprocessor.preprocess(istrpreproc, actual, "test.c");
@@ -6507,7 +6507,7 @@ class TestMemleakWindows : public TestFixture {
65076507
errout.str("");
65086508

65096509
// Preprocess...
6510-
Preprocessor preprocessor(&settings, this);
6510+
Preprocessor preprocessor(settings, this);
65116511
std::istringstream istrpreproc(code);
65126512
std::map<std::string, std::string> actual;
65136513
preprocessor.preprocess(istrpreproc, actual, "test.c");

test/testother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class TestOther : public TestFixture {
183183
settings->experimental = experimental;
184184

185185
// Preprocess file..
186-
Preprocessor preprocessor(settings);
186+
Preprocessor preprocessor(*settings);
187187
std::list<std::string> configurations;
188188
std::string filedata = "";
189189
std::istringstream fin(raw_code);
@@ -237,7 +237,7 @@ class TestOther : public TestFixture {
237237

238238
// Preprocess file..
239239
SimpleSuppressor logger(settings, this);
240-
Preprocessor preprocessor(&settings, &logger);
240+
Preprocessor preprocessor(settings, &logger);
241241
std::list<std::string> configurations;
242242
std::string filedata = "";
243243
std::istringstream fin(precode);

0 commit comments

Comments
 (0)