From: Anders Carlsson Date: Fri, 4 Dec 2009 15:49:02 +0000 (+0000) Subject: Change getIndex to return false if the index wasn't found. Avoids an extra hash lookup. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=77c23e5a49c30f829bf041a88ad6c60e6b662cc9;p=clang Change getIndex to return false if the index wasn't found. Avoids an extra hash lookup. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90568 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 96e5fc5837..e6b37555d6 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -91,15 +91,17 @@ private: MethodToIndexMap[GD] = Index; } - bool hasIndex(GlobalDecl GD) const { - return MethodToIndexMap.count(GD); - } - - /// getIndex - Returns the index of the given method. - uint64_t getIndex(GlobalDecl GD) const { - assert(MethodToIndexMap.count(GD) && "Did not find method!"); + /// getIndex - Gives the index of a passed in GlobalDecl. Returns false if + /// the index couldn't be found. + uint64_t getIndex(GlobalDecl GD, uint64_t &Index) const { + llvm::DenseMap::const_iterator i + = MethodToIndexMap.find(GD); + + if (i == MethodToIndexMap.end()) + return false; - return MethodToIndexMap.lookup(GD); + Index = i->second; + return true; } MethodsVectorTy::size_type size() const { @@ -741,11 +743,10 @@ bool VtableBuilder::OverrideMethod(GlobalDecl GD, bool MorallyVirtual, OGD = OMD; // FIXME: Explain why this is necessary! - if (!Methods.hasIndex(OGD)) + uint64_t Index; + if (!Methods.getIndex(OGD, Index)) continue; - uint64_t Index = Methods.getIndex(OGD); - QualType ReturnType = MD->getType()->getAs()->getResultType(); QualType OverriddenReturnType =