diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-07-22 18:44:36 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-07-22 18:44:36 +0000 |
| commit | 5d1c02748f2628a7c9e12819bb61a81783e204a5 (patch) | |
| tree | a5b5c598c49be780da9666ba6ad29b756fb6daee /clang/Lex | |
| parent | 619c17456120274a23cac74b6584c192bef77a3f (diff) | |
| download | bcm5719-llvm-5d1c02748f2628a7c9e12819bb61a81783e204a5.tar.gz bcm5719-llvm-5d1c02748f2628a7c9e12819bb61a81783e204a5.zip | |
Change hte lexer to start a start pointer to the underlying
memorybuffer instead of a pointer to the memorybuffer itself. This
reduces coupling and eliminates a pointer dereference on a hot path.
This speeds up -Eonly on 483.xalancbmk by 2.1%
llvm-svn: 40394
Diffstat (limited to 'clang/Lex')
| -rw-r--r-- | clang/Lex/Lexer.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/clang/Lex/Lexer.cpp b/clang/Lex/Lexer.cpp index 84cec226918..f23d34ed422 100644 --- a/clang/Lex/Lexer.cpp +++ b/clang/Lex/Lexer.cpp @@ -40,13 +40,19 @@ Lexer::Lexer(SourceLocation fileloc, Preprocessor &pp, : FileLoc(fileloc), PP(pp), Features(PP.getLangOptions()) { SourceManager &SourceMgr = PP.getSourceManager(); - InputFile =SourceMgr.getBuffer(SourceMgr.getPhysicalLoc(FileLoc).getFileID()); + unsigned InputFileID = SourceMgr.getPhysicalLoc(FileLoc).getFileID(); + const llvm::MemoryBuffer *InputFile = SourceMgr.getBuffer(InputFileID); Is_PragmaLexer = false; IsMainFile = false; InitCharacterInfo(); - - BufferPtr = BufStart ? BufStart : InputFile->getBufferStart(); + + // BufferStart must always be InputFile->getBufferStart(). + BufferStart = InputFile->getBufferStart(); + + // BufferPtr and BufferEnd can start out somewhere inside the current buffer. + // If unspecified, they starts at the start/end of the buffer. + BufferPtr = BufStart ? BufStart : BufferStart; BufferEnd = BufEnd ? BufEnd : InputFile->getBufferEnd(); assert(BufferEnd[0] == 0 && @@ -177,12 +183,12 @@ static SourceLocation GetMappedTokenLoc(Preprocessor &PP, /// getSourceLocation - Return a source location identifier for the specified /// offset in the current file. SourceLocation Lexer::getSourceLocation(const char *Loc) const { - assert(Loc >= InputFile->getBufferStart() && Loc <= BufferEnd && + assert(Loc >= BufferStart && Loc <= BufferEnd && "Location out of range for this buffer!"); // In the normal case, we're just lexing from a simple file buffer, return // the file id from FileLoc with the offset specified. - unsigned CharNo = Loc-InputFile->getBufferStart(); + unsigned CharNo = Loc-BufferStart; if (FileLoc.isFileID()) return SourceLocation::getFileLoc(FileLoc.getFileID(), CharNo); |

