SIL: Add a lookup cache StringMap to SILModule.

Because doing linear lookup all the time is dumb. NFC.

Swift SVN r11575
This commit is contained in:
Joe Groff
2013-12-22 22:37:55 +00:00
parent 41276a6d04
commit fd7b61ac71
3 changed files with 22 additions and 7 deletions

View File

@@ -50,6 +50,23 @@ SILModule::~SILModule() {
delete (SILTypeListUniquingType*)TypeListUniquing;
}
SILFunction *SILModule::lookup(StringRef Name) {
// Did we already find this?
auto found = FunctionLookupCache.find(Name);
if (found != FunctionLookupCache.end()) {
return found->second;
}
// If not, search through the function list, caching the entries we visit.
for (SILFunction &F : *this) {
FunctionLookupCache[F.getName()] = &F;
if (F.getName() == Name) {
return &F;
}
}
return nullptr;
}
SILFunction *SILModule::getOrCreateSharedFunction(SILLocation loc,
StringRef name,
CanSILFunctionType type,