Skip to content

Commit ac52954

Browse files
committedDec 5, 2018
[Basic] Cleanups in IdentifierInfo following the removal of PTH
The Entry pointer in IdentifierInfo was only null for IdentifierInfo created from a PTH. Now that PTH support has been removed we can remove some PTH specific code in IdentifierInfo::getLength and IdentifierInfo::getNameStart. Also make the constructor of IdentifierInfo private to make sure that they are only created by IdentifierTable, and move it to the header so that it can be inlined in IdentifierTable::get and IdentifierTable::getOwn. Differential Revision: https://reviews.llvm.org/D54866 Reviewed By: erichkeane llvm-svn: 348384
1 parent 33a448f commit ac52954

File tree

2 files changed

+12
-46
lines changed

2 files changed

+12
-46
lines changed
 

‎clang/include/clang/Basic/IdentifierTable.h

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,19 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
116116

117117
llvm::StringMapEntry<IdentifierInfo *> *Entry = nullptr;
118118

119+
IdentifierInfo()
120+
: TokenID(tok::identifier), ObjCOrBuiltinID(0), HasMacro(false),
121+
HadMacro(false), IsExtension(false), IsFutureCompatKeyword(false),
122+
IsPoisoned(false), IsCPPOperatorKeyword(false),
123+
NeedsHandleIdentifier(false), IsFromAST(false), ChangedAfterLoad(false),
124+
FEChangedAfterLoad(false), RevertedTokenID(false), OutOfDate(false),
125+
IsModulesImport(false) {}
126+
119127
public:
120-
IdentifierInfo();
121128
IdentifierInfo(const IdentifierInfo &) = delete;
122129
IdentifierInfo &operator=(const IdentifierInfo &) = delete;
130+
IdentifierInfo(IdentifierInfo &&) = delete;
131+
IdentifierInfo &operator=(IdentifierInfo &&) = delete;
123132

124133
/// Return true if this is the identifier for the specified string.
125134
///
@@ -138,31 +147,10 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
138147

139148
/// Return the beginning of the actual null-terminated string for this
140149
/// identifier.
141-
const char *getNameStart() const {
142-
if (Entry) return Entry->getKeyData();
143-
// FIXME: This is gross. It would be best not to embed specific details
144-
// of the PTH file format here.
145-
// The 'this' pointer really points to a
146-
// std::pair<IdentifierInfo, const char*>, where internal pointer
147-
// points to the external string data.
148-
using actualtype = std::pair<IdentifierInfo, const char *>;
149-
150-
return ((const actualtype*) this)->second;
151-
}
150+
const char *getNameStart() const { return Entry->getKeyData(); }
152151

153152
/// Efficiently return the length of this identifier info.
154-
unsigned getLength() const {
155-
if (Entry) return Entry->getKeyLength();
156-
// FIXME: This is gross. It would be best not to embed specific details
157-
// of the PTH file format here.
158-
// The 'this' pointer really points to a
159-
// std::pair<IdentifierInfo, const char*>, where internal pointer
160-
// points to the external string data.
161-
using actualtype = std::pair<IdentifierInfo, const char *>;
162-
163-
const char* p = ((const actualtype*) this)->second - 2;
164-
return (((unsigned) p[0]) | (((unsigned) p[1]) << 8)) - 1;
165-
}
153+
unsigned getLength() const { return Entry->getKeyLength(); }
166154

167155
/// Return the actual identifier string.
168156
StringRef getName() const {

‎clang/lib/Basic/IdentifierTable.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,6 @@
3333

3434
using namespace clang;
3535

36-
//===----------------------------------------------------------------------===//
37-
// IdentifierInfo Implementation
38-
//===----------------------------------------------------------------------===//
39-
40-
IdentifierInfo::IdentifierInfo() {
41-
TokenID = tok::identifier;
42-
ObjCOrBuiltinID = 0;
43-
HasMacro = false;
44-
HadMacro = false;
45-
IsExtension = false;
46-
IsFutureCompatKeyword = false;
47-
IsPoisoned = false;
48-
IsCPPOperatorKeyword = false;
49-
NeedsHandleIdentifier = false;
50-
IsFromAST = false;
51-
ChangedAfterLoad = false;
52-
FEChangedAfterLoad = false;
53-
RevertedTokenID = false;
54-
OutOfDate = false;
55-
IsModulesImport = false;
56-
}
57-
5836
//===----------------------------------------------------------------------===//
5937
// IdentifierTable Implementation
6038
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)
Please sign in to comment.