diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-01-15 18:47:46 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-01-15 18:47:46 +0000 |
commit | 72b1b15ee88aac0a63e2c1dc53fe22f5ab297b20 (patch) | |
tree | 525dfef2340cc9e228a1be10104d902ef7d9eaee /Driver/CacheTokens.cpp | |
parent | f185319f25efd6094870f287030270fad26085ba (diff) |
IdentifierInfo:
- IdentifierInfo can now (optionally) have its string data not be
co-located with itself. This is for use with PTH. This aspect is a
little gross, as getName() and getLength() now make assumptions
about a possible alternate representation of IdentifierInfo.
Perhaps we should make IdentifierInfo have virtual methods?
IdentifierTable:
- Added class "IdentifierInfoLookup" that can be used by
IdentifierTable to perform "string -> IdentifierInfo" lookups using
an auxilliary data structure. This is used by PTH.
- Perform tests show that IdentifierTable::get() does not slow down
because of the extra check for the IdentiferInfoLookup object (the
regular StringMap lookup does enough work to mitigate the impact of
an extra null pointer check).
- The upshot is that now that some IdentifierInfo objects might be
owned by the IdentiferInfoLookup object. This should be reviewed.
PTH:
- Modified PTHManager::GetIdentifierInfo to *not* insert entries in
IdentifierTable's string map, and instead create IdentifierInfo
objects on the fly when mapping from persistent IDs to
IdentifierInfos. This saves a ton of work with string copies,
hashing, and StringMap lookup and resizing. This change was
motivated because when processing source files in the PTH cache we
don't need to do any string -> IdentifierInfo lookups.
- PTHManager now subclasses IdentifierInfoLookup, allowing clients of
IdentifierTable to transparently use IdentifierInfo objects managed
by the PTH file. PTHManager resolves "string -> IdentifierInfo"
queries by doing a binary search over a sorted table of identifier
strings in the PTH file (the exact algorithm we use can be changed
as needed).
These changes lead to the following performance changes when using PTH on Cocoa.h:
- fsyntax-only: 10% performance improvement
- Eonly: 30% performance improvement
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62273 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Driver/CacheTokens.cpp')
-rw-r--r-- | Driver/CacheTokens.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/Driver/CacheTokens.cpp b/Driver/CacheTokens.cpp index 2548d3d7dd..d791e09d6c 100644 --- a/Driver/CacheTokens.cpp +++ b/Driver/CacheTokens.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/System/Path.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Streams.h" using namespace clang; @@ -179,8 +180,20 @@ public: CompareIDDataIndex(IDData* table) : Table(table) {} bool operator()(unsigned i, unsigned j) const { - // Assume that IdentifierInfo::getName() returns a '\0' terminated string. - return strcmp(Table[i].II->getName(), Table[j].II->getName()) < 0; + const IdentifierInfo* II_i = Table[i].II; + const IdentifierInfo* II_j = Table[j].II; + + unsigned i_len = II_i->getLength(); + unsigned j_len = II_j->getLength(); + + if (i_len > j_len) + return false; + + if (i_len < j_len) + return true; + + // Otherwise, compare the strings themselves! + return strncmp(II_i->getName(), II_j->getName(), i_len) < 0; } }; } @@ -221,7 +234,10 @@ PTHWriter::EmitIdentifierTable() { unsigned len = d.II->getLength(); // Write out the string length. Emit32(len); const char* buf = d.II->getName(); // Write out the string data. - EmitBuf(buf, buf+len); + EmitBuf(buf, buf+len); + // Emit a null character for those clients expecting that IdentifierInfo + // strings are null terminated. + Emit8('\0'); } // Now emit the table mapping from persistent IDs to PTH file offsets. @@ -229,7 +245,6 @@ PTHWriter::EmitIdentifierTable() { Emit32(idcount); // Emit the number of identifiers. for (unsigned i = 0 ; i < idcount; ++i) Emit32(IIDMap[i].FileOffset); - return std::make_pair(DataOff, std::make_pair(IDOff, LexicalOff)); } |