summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2014-08-29 19:36:52 +0000
committerDavid Blaikie <dblaikie@gmail.com>2014-08-29 19:36:52 +0000
commit6d5038c19c1ed84d3a3a0d6cc7011933d927d1dd (patch)
tree01b9a3f03a893caf8b188d38c107472c0cf77822 /clang
parente90195c09b20d3d49c346ee6bc0f62e505cc5573 (diff)
downloadbcm5719-llvm-6d5038c19c1ed84d3a3a0d6cc7011933d927d1dd.tar.gz
bcm5719-llvm-6d5038c19c1ed84d3a3a0d6cc7011933d927d1dd.zip
unique_ptrify Preprocessor's TokenLexerCache
llvm-svn: 216756
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Lex/Preprocessor.h2
-rw-r--r--clang/lib/Lex/PPLexerChange.cpp22
-rw-r--r--clang/lib/Lex/Preprocessor.cpp3
3 files changed, 13 insertions, 14 deletions
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index e1896e4789d..8e352b78e13 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -395,7 +395,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> {
/// \brief Cache of macro expanders to reduce malloc traffic.
enum { TokenLexerCacheSize = 8 };
unsigned NumCachedTokenLexers;
- TokenLexer *TokenLexerCache[TokenLexerCacheSize];
+ std::unique_ptr<TokenLexer> TokenLexerCache[TokenLexerCacheSize];
/// \}
/// \brief Keeps macro expanded tokens for TokenLexers.
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 22ee971f488..1ce3796aa79 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -160,17 +160,17 @@ void Preprocessor::EnterSourceFileWithPTH(PTHLexer *PL,
/// tokens from it instead of the current buffer.
void Preprocessor::EnterMacro(Token &Tok, SourceLocation ILEnd,
MacroInfo *Macro, MacroArgs *Args) {
- TokenLexer *TokLexer;
+ std::unique_ptr<TokenLexer> TokLexer;
if (NumCachedTokenLexers == 0) {
- TokLexer = new TokenLexer(Tok, ILEnd, Macro, Args, *this);
+ TokLexer = llvm::make_unique<TokenLexer>(Tok, ILEnd, Macro, Args, *this);
} else {
- TokLexer = TokenLexerCache[--NumCachedTokenLexers];
+ TokLexer = std::move(TokenLexerCache[--NumCachedTokenLexers]);
TokLexer->Init(Tok, ILEnd, Macro, Args);
}
PushIncludeMacroStack();
CurDirLookup = nullptr;
- CurTokenLexer.reset(TokLexer);
+ CurTokenLexer = std::move(TokLexer);
if (CurLexerKind != CLK_LexAfterModuleImport)
CurLexerKind = CLK_TokenLexer;
}
@@ -191,19 +191,19 @@ void Preprocessor::EnterTokenStream(const Token *Toks, unsigned NumToks,
bool DisableMacroExpansion,
bool OwnsTokens) {
// Create a macro expander to expand from the specified token stream.
- TokenLexer *TokLexer;
+ std::unique_ptr<TokenLexer> TokLexer;
if (NumCachedTokenLexers == 0) {
- TokLexer = new TokenLexer(Toks, NumToks, DisableMacroExpansion,
- OwnsTokens, *this);
+ TokLexer = llvm::make_unique<TokenLexer>(
+ Toks, NumToks, DisableMacroExpansion, OwnsTokens, *this);
} else {
- TokLexer = TokenLexerCache[--NumCachedTokenLexers];
+ TokLexer = std::move(TokenLexerCache[--NumCachedTokenLexers]);
TokLexer->Init(Toks, NumToks, DisableMacroExpansion, OwnsTokens);
}
// Save our current state.
PushIncludeMacroStack();
CurDirLookup = nullptr;
- CurTokenLexer.reset(TokLexer);
+ CurTokenLexer = std::move(TokLexer);
if (CurLexerKind != CLK_LexAfterModuleImport)
CurLexerKind = CLK_TokenLexer;
}
@@ -526,7 +526,7 @@ bool Preprocessor::HandleEndOfTokenLexer(Token &Result) {
if (NumCachedTokenLexers == TokenLexerCacheSize)
CurTokenLexer.reset();
else
- TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.release();
+ TokenLexerCache[NumCachedTokenLexers++] = std::move(CurTokenLexer);
// Handle this like a #include file being popped off the stack.
return HandleEndOfFile(Result, true);
@@ -543,7 +543,7 @@ void Preprocessor::RemoveTopOfLexerStack() {
if (NumCachedTokenLexers == TokenLexerCacheSize)
CurTokenLexer.reset();
else
- TokenLexerCache[NumCachedTokenLexers++] = CurTokenLexer.release();
+ TokenLexerCache[NumCachedTokenLexers++] = std::move(CurTokenLexer);
}
PopIncludeMacroStack();
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index faf5bbb38b9..2c23d682820 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -151,8 +151,7 @@ Preprocessor::~Preprocessor() {
// Free any cached macro expanders.
// This populates MacroArgCache, so all TokenLexers need to be destroyed
// before the code below that frees up the MacroArgCache list.
- for (unsigned i = 0, e = NumCachedTokenLexers; i != e; ++i)
- delete TokenLexerCache[i];
+ std::fill(TokenLexerCache, TokenLexerCache + NumCachedTokenLexers, nullptr);
CurTokenLexer.reset();
while (DeserializedMacroInfoChain *I = DeserialMIChainHead) {
OpenPOWER on IntegriCloud