r216786 - unique_ptrify PTHManager's PerIDCache using the newly added llvm::FreeDeleter
David Blaikie
dblaikie at gmail.com
Fri Aug 29 15:04:46 PDT 2014
Author: dblaikie
Date: Fri Aug 29 17:04:45 2014
New Revision: 216786
URL: http://llvm.org/viewvc/llvm-project?rev=216786&view=rev
Log:
unique_ptrify PTHManager's PerIDCache using the newly added llvm::FreeDeleter
Modified:
cfe/trunk/include/clang/Lex/PTHManager.h
cfe/trunk/lib/Lex/PTHLexer.cpp
Modified: cfe/trunk/include/clang/Lex/PTHManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHManager.h?rev=216786&r1=216785&r2=216786&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PTHManager.h (original)
+++ cfe/trunk/include/clang/Lex/PTHManager.h Fri Aug 29 17:04:45 2014
@@ -52,7 +52,7 @@ class PTHManager : public IdentifierInfo
/// IdMap - A lazily generated cache mapping from persistent identifiers to
/// IdentifierInfo*.
- IdentifierInfo** PerIDCache;
+ std::unique_ptr<IdentifierInfo *[], llvm::FreeDeleter> PerIDCache;
/// FileLookup - Abstract data structure used for mapping between files
/// and token data in the PTH file.
@@ -86,7 +86,8 @@ class PTHManager : public IdentifierInfo
/// method.
PTHManager(std::unique_ptr<const llvm::MemoryBuffer> buf,
std::unique_ptr<PTHFileLookup> fileLookup,
- const unsigned char *idDataTable, IdentifierInfo **perIDCache,
+ const unsigned char *idDataTable,
+ std::unique_ptr<IdentifierInfo *[], llvm::FreeDeleter> perIDCache,
std::unique_ptr<PTHStringIdLookup> stringIdLookup, unsigned numIds,
const unsigned char *spellingBase, const char *originalSourceFile);
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=216786&r1=216785&r2=216786&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Fri Aug 29 17:04:45 2014
@@ -413,20 +413,18 @@ public:
// PTHManager methods.
//===----------------------------------------------------------------------===//
-PTHManager::PTHManager(std::unique_ptr<const llvm::MemoryBuffer> buf,
- std::unique_ptr<PTHFileLookup> fileLookup,
- const unsigned char *idDataTable,
- IdentifierInfo **perIDCache,
- std::unique_ptr<PTHStringIdLookup> stringIdLookup,
- unsigned numIds, const unsigned char *spellingBase,
- const char *originalSourceFile)
- : Buf(std::move(buf)), PerIDCache(perIDCache),
+PTHManager::PTHManager(
+ std::unique_ptr<const llvm::MemoryBuffer> buf,
+ std::unique_ptr<PTHFileLookup> fileLookup, const unsigned char *idDataTable,
+ std::unique_ptr<IdentifierInfo *[], llvm::FreeDeleter> perIDCache,
+ std::unique_ptr<PTHStringIdLookup> stringIdLookup, unsigned numIds,
+ const unsigned char *spellingBase, const char *originalSourceFile)
+ : Buf(std::move(buf)), PerIDCache(std::move(perIDCache)),
FileLookup(std::move(fileLookup)), IdDataTable(idDataTable),
StringIdLookup(std::move(stringIdLookup)), NumIds(numIds), PP(nullptr),
SpellingBase(spellingBase), OriginalSourceFile(originalSourceFile) {}
PTHManager::~PTHManager() {
- free(PerIDCache);
}
static void InvalidPTH(DiagnosticsEngine &Diags, const char *Msg) {
@@ -537,10 +535,10 @@ PTHManager *PTHManager::Create(const std
// Pre-allocate the persistent ID -> IdentifierInfo* cache. We use calloc()
// so that we in the best case only zero out memory once when the OS returns
// us new pages.
- IdentifierInfo **PerIDCache = nullptr;
+ std::unique_ptr<IdentifierInfo *[], llvm::FreeDeleter> PerIDCache;
if (NumIds) {
- PerIDCache = (IdentifierInfo**)calloc(NumIds, sizeof(*PerIDCache));
+ PerIDCache.reset((IdentifierInfo **)calloc(NumIds, sizeof(PerIDCache[0])));
if (!PerIDCache) {
InvalidPTH(Diags, "Could not allocate memory for processing PTH file");
return nullptr;
@@ -554,9 +552,9 @@ PTHManager *PTHManager::Create(const std
if (!len) originalSourceBase = nullptr;
// Create the new PTHManager.
- return new PTHManager(std::move(File), std::move(FL), IData, PerIDCache,
- std::move(SL), NumIds, spellingBase,
- (const char *)originalSourceBase);
+ return new PTHManager(std::move(File), std::move(FL), IData,
+ std::move(PerIDCache), std::move(SL), NumIds,
+ spellingBase, (const char *)originalSourceBase);
}
IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) {
More information about the cfe-commits
mailing list