From 144aacd19ef6dc25755c69048d4cb3a4a383ae8a Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 18 Jan 2009 02:57:21 +0000 Subject: [PATCH] rearrange GetIdentifierInfo so that the fast path can be partially inlined into PTHLexer::Lex. This speeds up the user time of PTH -Eonly by another 2ms (4.4%) llvm-svn: 62454 --- clang/include/clang/Lex/PTHManager.h | 8 +++++++- clang/lib/Lex/PTHLexer.cpp | 14 ++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clang/include/clang/Lex/PTHManager.h b/clang/include/clang/Lex/PTHManager.h index b9d249332723..09cd9e9e3c92 100644 --- a/clang/include/clang/Lex/PTHManager.h +++ b/clang/include/clang/Lex/PTHManager.h @@ -109,7 +109,13 @@ class PTHManager : public IdentifierInfoLookup { /// GetIdentifierInfo - Used to reconstruct IdentifierInfo objects from the /// PTH file. - IdentifierInfo* GetIdentifierInfo(unsigned); + inline IdentifierInfo* GetIdentifierInfo(unsigned PersistentID) { + // Check if the IdentifierInfo has already been resolved. + if (IdentifierInfo* II = PerIDCache[PersistentID]) + return II; + return LazilyCreateIdentifierInfo(PersistentID); + } + IdentifierInfo* LazilyCreateIdentifierInfo(unsigned PersistentID); public: ~PTHManager(); diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp index a1d7f5735ea1..7df8e35986e1 100644 --- a/clang/lib/Lex/PTHLexer.cpp +++ b/clang/lib/Lex/PTHLexer.cpp @@ -596,15 +596,9 @@ PTHManager* PTHManager::Create(const std::string& file) { return new PTHManager(File.take(), FL.take(), IData, PerIDCache, SortedIdTable, NumIds); } - -IdentifierInfo* PTHManager::GetIdentifierInfo(unsigned persistentID) { - - // Check if the IdentifierInfo has already been resolved. - IdentifierInfo* II = PerIDCache[persistentID]; - if (II) return II; - +IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) { // Look in the PTH file for the string data for the IdentifierInfo object. - const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*persistentID; + const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*PersistentID; const unsigned char* IDData = (const unsigned char*)Buf->getBufferStart() + Read32(TableEntry); assert(IDData < (const unsigned char*)Buf->getBufferEnd()); @@ -614,10 +608,10 @@ IdentifierInfo* PTHManager::GetIdentifierInfo(unsigned persistentID) { Alloc.Allocate >(); Mem->second = IDData; - II = new ((void*) Mem) IdentifierInfo(true); + IdentifierInfo *II = new ((void*) Mem) IdentifierInfo(true); // Store the new IdentifierInfo in the cache. - PerIDCache[persistentID] = II; + PerIDCache[PersistentID] = II; return II; }