[llvm-commits] CVS: llvm/include/llvm/ADT/SmallVector.h

Chris Lattner lattner at cs.uiuc.edu
Tue Aug 15 18:23:45 PDT 2006



Changes in directory llvm/include/llvm/ADT:

SmallVector.h updated: 1.12 -> 1.13
---
Log message:

Bugfixes for smallvector when the element size is small and N is small.


---
Diffs of the changes:  (+17 -4)

 SmallVector.h |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)


Index: llvm/include/llvm/ADT/SmallVector.h
diff -u llvm/include/llvm/ADT/SmallVector.h:1.12 llvm/include/llvm/ADT/SmallVector.h:1.13
--- llvm/include/llvm/ADT/SmallVector.h:1.12	Mon Aug 14 16:47:50 2006
+++ llvm/include/llvm/ADT/SmallVector.h	Tue Aug 15 20:23:31 2006
@@ -228,17 +228,30 @@
   /// InlineElts - These are 'N-1' elements that are stored inline in the body
   /// of the vector.  The extra '1' element is stored in SmallVectorImpl.
   typedef typename SmallVectorImpl<T>::U U;
-  U InlineElts[(sizeof(T)*N+sizeof(U)-1)/sizeof(U) - 1];
+  enum {
+    // MinUs - The number of U's require to cover N T's.
+    MinUs = (sizeof(T)*N+sizeof(U)-1)/sizeof(U),
+    
+    // NumInlineEltsElts - The number of elements actually in this array.  There
+    // is already one in the parent class, and we have to round up to avoid
+    // having a zero-element array.
+    NumInlineEltsElts = (MinUs - 1) > 0 ? (MinUs - 1) : 1,
+    
+    // NumTsAvailable - The number of T's we actually have space for, which may
+    // be more than N due to rounding.
+    NumTsAvailable = (NumInlineEltsElts+1)*sizeof(U) / sizeof(T)
+  };
+  U InlineElts[NumInlineEltsElts];
 public:  
-  SmallVector() : SmallVectorImpl<T>(N) {
+  SmallVector() : SmallVectorImpl<T>(NumTsAvailable) {
   }
   
   template<typename ItTy>
-  SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(N) {
+  SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(NumTsAvailable) {
     append(S, E);
   }
   
-  SmallVector(const SmallVector &RHS) : SmallVectorImpl<T>(N) {
+  SmallVector(const SmallVector &RHS) : SmallVectorImpl<T>(NumTsAvailable) {
     operator=(RHS);
   }
 };






More information about the llvm-commits mailing list