From e22b1f7740c7efad53d421b13d063444c47fbae4 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 16 Jan 2013 20:27:20 +0100 Subject: [PATCH] Adapt Tokenizer::simplifyCallingConvention() and Tokenizer::simplifyKeyword() for the match compiler This little change gives another 6% speed improvement on my box. (tested with the testsuite and checking the 'rpm' codebase) The profiler showed we were spending quite some time in Tokenizer::simplifyCallingConvention(). The multi match pattern in there is "complex", at least for the on-the-fly parser. --- lib/tokenize.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index edf6e79b8..1bba8bf8d 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8459,9 +8459,8 @@ void Tokenizer::simplifyStructDecl() void Tokenizer::simplifyCallingConvention() { - static const char pattern[] = "__cdecl|__stdcall|__fastcall|__thiscall|__clrcall|__syscall|__pascal|__fortran|__far|__near|WINAPI|APIENTRY|CALLBACK"; for (Token *tok = list.front(); tok; tok = tok->next()) { - while (Token::Match(tok, pattern)) { + while (Token::Match(tok, "__cdecl|__stdcall|__fastcall|__thiscall|__clrcall|__syscall|__pascal|__fortran|__far|__near|WINAPI|APIENTRY|CALLBACK")) { tok->deleteThis(); } } @@ -8505,17 +8504,27 @@ void Tokenizer::simplifyAttribute() // - Not in C++ standard yet void Tokenizer::simplifyKeyword() { - std::string pattern = "volatile|inline|__inline|__forceinline|register|__restrict|__restrict__"; - if (_settings->standards.c >= Standards::C99) - pattern += "|restrict"; - if (_settings->standards.cpp >= Standards::CPP11) - pattern += "|constexpr|override|final"; - for (Token *tok = list.front(); tok; tok = tok->next()) { - while (Token::Match(tok, pattern.c_str())) { + while (Token::Match(tok, "volatile|inline|__inline|__forceinline|register|__restrict|__restrict__")) { tok->deleteThis(); } } + + if (_settings->standards.c >= Standards::C99) { + for (Token *tok = list.front(); tok; tok = tok->next()) { + while (Token::Match(tok, "restrict")) { + tok->deleteThis(); + } + } + } + + if (_settings->standards.cpp >= Standards::CPP11) { + for (Token *tok = list.front(); tok; tok = tok->next()) { + while (Token::Match(tok, "constexpr|override|final")) { + tok->deleteThis(); + } + } + } } void Tokenizer::simplifyAssignmentInFunctionCall()