diff --git a/clang/Lex/IdentifierTable.cpp b/clang/Lex/IdentifierTable.cpp index 99c43422ebbc..0a84f5bd5fba 100644 --- a/clang/Lex/IdentifierTable.cpp +++ b/clang/Lex/IdentifierTable.cpp @@ -23,7 +23,18 @@ using namespace clang; // IdentifierInfo Implementation //===----------------------------------------------------------------------===// -void IdentifierInfo::Destroy() { +IdentifierInfo::IdentifierInfo() { + Macro = 0; + TokenID = tok::identifier; + PPID = tok::pp_not_keyword; + ObjCID = tok::objc_not_keyword; + IsExtension = false; + IsPoisoned = false; + IsOtherTargetMacro = false; + FETokenInfo = 0; +} + +IdentifierInfo::~IdentifierInfo() { delete Macro; } @@ -146,7 +157,7 @@ IdentifierTable::~IdentifierTable() { for (unsigned i = 0, e = HashTableSize; i != e; ++i) { if (IdentifierInfo *Id = TableArray[i].Info) { // Free memory referenced by the identifier (e.g. macro info). - Id->Destroy(); + Id->~IdentifierInfo(); #if !USE_ALLOCATOR // Free the memory for the identifier itself. @@ -214,14 +225,7 @@ IdentifierInfo &IdentifierTable::get(const char *NameStart, #else IdentifierInfo *Identifier = (IdentifierInfo*)malloc(AllocSize); #endif - Identifier->Macro = 0; - Identifier->TokenID = tok::identifier; - Identifier->PPID = tok::pp_not_keyword; - Identifier->ObjCID = tok::objc_not_keyword; - Identifier->IsExtension = false; - Identifier->IsPoisoned = false; - Identifier->IsOtherTargetMacro = false; - Identifier->FETokenInfo = 0; + new (Identifier) IdentifierInfo(); ++NumIdentifiers; // Copy the string information. diff --git a/clang/include/clang/Lex/IdentifierTable.h b/clang/include/clang/Lex/IdentifierTable.h index 6ba19bdcd389..32e5bcb9f238 100644 --- a/clang/include/clang/Lex/IdentifierTable.h +++ b/clang/include/clang/Lex/IdentifierTable.h @@ -39,7 +39,11 @@ class IdentifierInfo { bool IsOtherTargetMacro : 1; // True if ident is macro on another target. void *FETokenInfo; // Managed by the language front-end. friend class IdentifierTable; + IdentifierInfo(const IdentifierInfo&); // NONCOPYABLE. public: + IdentifierInfo(); + ~IdentifierInfo(); + /// getName - Return the actual string for this identifier. The length of /// this string is stored in NameLen, and the returned string is properly null /// terminated. @@ -94,8 +98,6 @@ public: template T *getFETokenInfo() const { return static_cast(FETokenInfo); } void setFETokenInfo(void *T) { FETokenInfo = T; } -private: - void Destroy(); }; /// IdentifierVisitor - Subclasses of this class may be implemented to walk all