diff options
author | Bruno Ricci <riccibrun@gmail.com> | 2019-03-25 17:08:51 +0000 |
---|---|---|
committer | Bruno Ricci <riccibrun@gmail.com> | 2019-03-25 17:08:51 +0000 |
commit | 70ad396bc49a96f39b7b4fe4c8d3034a4f606022 (patch) | |
tree | 2650ae136d66269ed280807e3adc29ff18afaba5 /clang/lib/Parse/ParseTentative.cpp | |
parent | 2224181dad5a8435c42eef6f0057f68807a382ca (diff) | |
download | bcm5719-llvm-70ad396bc49a96f39b7b4fe4c8d3034a4f606022.tar.gz bcm5719-llvm-70ad396bc49a96f39b7b4fe4c8d3034a4f606022.zip |
[Sema][NFCI] Don't allocate storage for the various CorrectionCandidateCallback unless we are going to do some typo correction
The various CorrectionCandidateCallbacks are currently heap-allocated
unconditionally. This was needed because of delayed typo correction.
However these allocations represent currently 15.4% of all allocations
(number of allocations) when parsing all of Boost (!), mostly because
of ParseCastExpression, ParseStatementOrDeclarationAfterAttrtibutes
and isCXXDeclarationSpecifier. Note that all of these callback objects
are small. Let's not do this.
Instead initially allocate the callback on the stack, and only do a
heap allocation if we are going to do some typo correction. Do this by:
1. Adding a clone function to each callback, which will do a polymorphic
clone of the callback. This clone function is required to be implemented
by every callback (of which there is a fair amount). Make sure this is
the case by making it pure virtual.
2. Use this clone function when we are going to try to correct a typo.
This additionally cut the time of -fsyntax-only on all of Boost by 0.5%
(not that much, but still something). No functional changes intended.
Differential Revision: https://reviews.llvm.org/D58827
Reviewed By: rnk
llvm-svn: 356925
Diffstat (limited to 'clang/lib/Parse/ParseTentative.cpp')
-rw-r--r-- | clang/lib/Parse/ParseTentative.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp index 81079cda949..d0549a9725d 100644 --- a/clang/lib/Parse/ParseTentative.cpp +++ b/clang/lib/Parse/ParseTentative.cpp @@ -1147,7 +1147,7 @@ bool Parser::isTentativelyDeclared(IdentifierInfo *II) { } namespace { -class TentativeParseCCC : public CorrectionCandidateCallback { +class TentativeParseCCC final : public CorrectionCandidateCallback { public: TentativeParseCCC(const Token &Next) { WantRemainingKeywords = false; @@ -1165,6 +1165,10 @@ public: return CorrectionCandidateCallback::ValidateCandidate(Candidate); } + + std::unique_ptr<CorrectionCandidateCallback> clone() override { + return llvm::make_unique<TentativeParseCCC>(*this); + } }; } /// isCXXDeclarationSpecifier - Returns TPResult::True if it is a declaration @@ -1293,8 +1297,8 @@ Parser::isCXXDeclarationSpecifier(Parser::TPResult BracedCastResult, // a parse error one way or another. In that case, tell the caller that // this is ambiguous. Typo-correct to type and expression keywords and // to types and identifiers, in order to try to recover from errors. - switch (TryAnnotateName(false /* no nested name specifier */, - llvm::make_unique<TentativeParseCCC>(Next))) { + TentativeParseCCC CCC(Next); + switch (TryAnnotateName(false /* no nested name specifier */, &CCC)) { case ANK_Error: return TPResult::Error; case ANK_TentativeDecl: |