Make getContainedType more efficient by not returning null if out of range!
authorChris Lattner <sabre@nondot.org>
Thu, 9 Oct 2003 20:35:15 +0000 (20:35 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 9 Oct 2003 20:35:15 +0000 (20:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8987 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DerivedTypes.h
include/llvm/Type.h

index 57a8c02e4d8d6c178148954da4df5137f3dbec00..e0ccffd5fb7e9371e01d48b437a86e5a0b3bab8b 100644 (file)
@@ -156,8 +156,7 @@ public:
 
 
   virtual const Type *getContainedType(unsigned i) const {
-    return i == 0 ? ResultType : 
-                    (i <= ParamTys.size() ? ParamTys[i-1].get() : 0);
+    return i == 0 ? ResultType.get() : ParamTys[i-1].get();
   }
   virtual unsigned getNumContainedTypes() const { return ParamTys.size()+1; }
 
@@ -239,7 +238,7 @@ public:
   inline const ElementTypes &getElementTypes() const { return ETypes; }
 
   virtual const Type *getContainedType(unsigned i) const { 
-    return i < ETypes.size() ? ETypes[i].get() : 0;
+    return ETypes[i].get();
   }
   virtual unsigned getNumContainedTypes() const { return ETypes.size(); }
 
@@ -289,7 +288,7 @@ public:
   inline const Type *getElementType() const { return ElementType; }
 
   virtual const Type *getContainedType(unsigned i) const { 
-    return i == 0 ? ElementType.get() : 0;
+    return ElementType.get();
   }
   virtual unsigned getNumContainedTypes() const { return 1; }
 
index 5900b402dcc4931e278388d21bfd679a4fb4badf..3ed2d2dd7abb611e22bd954c6b0bc8eac2f2fa3b 100644 (file)
@@ -202,11 +202,11 @@ public:
 
   /// getContainedType - This method is used to implement the type iterator
   /// (defined a the end of the file).  For derived types, this returns the
-  /// types 'contained' in the derived type, returning 0 when 'i' becomes
-  /// invalid. This allows the user to iterate over the types in a struct, for
-  /// example, really easily.
+  /// types 'contained' in the derived type.
   ///
-  virtual const Type *getContainedType(unsigned i) const { return 0; }
+  virtual const Type *getContainedType(unsigned i) const {
+    assert(0 && "No contained types!");
+  }
 
   /// getNumContainedTypes - Return the number of types in the derived type
   virtual unsigned getNumContainedTypes() const { return 0; }