StringRefize Preprocessor::getIdentifierInfo.

llvm-svn: 86105
This commit is contained in:
Daniel Dunbar 2009-11-05 01:53:39 +00:00
parent c00be15469
commit f539bfeb4d
2 changed files with 4 additions and 8 deletions

View File

@ -296,12 +296,8 @@ public:
/// pointers is preferred unless the identifier is already available as a /// pointers is preferred unless the identifier is already available as a
/// string (this avoids allocation and copying of memory to construct an /// string (this avoids allocation and copying of memory to construct an
/// std::string). /// std::string).
IdentifierInfo *getIdentifierInfo(const char *NameStart, IdentifierInfo *getIdentifierInfo(llvm::StringRef Name) {
const char *NameEnd) { return &Identifiers.get(Name);
return &Identifiers.get(NameStart, NameEnd);
}
IdentifierInfo *getIdentifierInfo(const char *NameStr) {
return getIdentifierInfo(NameStr, NameStr+strlen(NameStr));
} }
/// AddPragmaHandler - Add the specified pragma handler to the preprocessor. /// AddPragmaHandler - Add the specified pragma handler to the preprocessor.

View File

@ -409,14 +409,14 @@ IdentifierInfo *Preprocessor::LookUpIdentifierInfo(Token &Identifier,
IdentifierInfo *II; IdentifierInfo *II;
if (BufPtr && !Identifier.needsCleaning()) { if (BufPtr && !Identifier.needsCleaning()) {
// No cleaning needed, just use the characters from the lexed buffer. // No cleaning needed, just use the characters from the lexed buffer.
II = getIdentifierInfo(BufPtr, BufPtr+Identifier.getLength()); II = getIdentifierInfo(llvm::StringRef(BufPtr, Identifier.getLength()));
} else { } else {
// Cleaning needed, alloca a buffer, clean into it, then use the buffer. // Cleaning needed, alloca a buffer, clean into it, then use the buffer.
llvm::SmallVector<char, 64> IdentifierBuffer; llvm::SmallVector<char, 64> IdentifierBuffer;
IdentifierBuffer.resize(Identifier.getLength()); IdentifierBuffer.resize(Identifier.getLength());
const char *TmpBuf = &IdentifierBuffer[0]; const char *TmpBuf = &IdentifierBuffer[0];
unsigned Size = getSpelling(Identifier, TmpBuf); unsigned Size = getSpelling(Identifier, TmpBuf);
II = getIdentifierInfo(TmpBuf, TmpBuf+Size); II = getIdentifierInfo(llvm::StringRef(TmpBuf, Size));
} }
Identifier.setIdentifierInfo(II); Identifier.setIdentifierInfo(II);
return II; return II;