]> granicus.if.org Git - clang/commitdiff
Change getIndex to return false if the index wasn't found. Avoids an extra hash lookup.
authorAnders Carlsson <andersca@mac.com>
Fri, 4 Dec 2009 15:49:02 +0000 (15:49 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 4 Dec 2009 15:49:02 +0000 (15:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90568 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGVtable.cpp

index 96e5fc58377d344c35334854525fcc688e2ec6a2..e6b37555d652b6426a0e513260a0c6e768de60bc 100644 (file)
@@ -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<GlobalDecl, uint64_t>::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<FunctionType>()->getResultType();
     QualType OverriddenReturnType =