Make C++ Parser::exitRule() non-virtual

Parser::exitRule() in the C++ runtime is a virtual function which is not
reimplemented anywhere. OTOH, it is invoked during the execution of
every rule, which can cause a noticeable performance hit. This commit
removes its virtual qualifier. It should make a difference particularly
for large grammars, because the number of rules corresponds to the
number of the Parser object's virtual functions, and, consequently, its
vtable lookup time.

Tested with a VHDL grammar of 436 rules, where it brings down parsing
time from 75 to 44 seconds on unoptimized compilation, i.e. a 40% speed
gain.  Still a lot slower than an equivalent java parser, though, which
takes 2.64 seconds for the same input.
This commit is contained in:
Jan Lindemann 2017-12-10 11:30:21 +01:00
parent 2634246b07
commit 4e3c5ddffb
1 changed files with 1 additions and 1 deletions

View File

@ -272,7 +272,7 @@ namespace antlr4 {
/// <seealso cref="#_ctx"/> get the current context. /// <seealso cref="#_ctx"/> get the current context.
virtual void enterRule(ParserRuleContext *localctx, size_t state, size_t ruleIndex); virtual void enterRule(ParserRuleContext *localctx, size_t state, size_t ruleIndex);
virtual void exitRule(); void exitRule();
virtual void enterOuterAlt(ParserRuleContext *localctx, size_t altNum); virtual void enterOuterAlt(ParserRuleContext *localctx, size_t altNum);