[llvm] r253180 - [ADT] Make capacity_in_bytes support BitVector. NFC.

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 15 20:02:37 PST 2015


Author: vedantk
Date: Sun Nov 15 22:02:36 2015
New Revision: 253180

URL: http://llvm.org/viewvc/llvm-project?rev=253180&view=rev
Log:
[ADT] Make capacity_in_bytes support BitVector. NFC.

This makes it a bit easier to replace instances of vector<bool> with
BitVector.

Modified:
    llvm/trunk/include/llvm/ADT/BitVector.h

Modified: llvm/trunk/include/llvm/ADT/BitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=253180&r1=253179&r2=253180&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/BitVector.h Sun Nov 15 22:02:36 2015
@@ -34,7 +34,7 @@ class BitVector {
 
   BitWord  *Bits;        // Actual bits.
   unsigned Size;         // Size of bitvector in bits.
-  unsigned Capacity;     // Size of allocated memory in BitWord.
+  unsigned Capacity;     // Number of BitWords allocated in the Bits array.
 
 public:
   typedef unsigned size_type;
@@ -566,8 +566,16 @@ private:
     if (AddBits)
       clear_unused_bits();
   }
+
+public:
+  /// Return the size (in bytes) of the bit vector.
+  size_t getMemorySize() const { return Capacity * sizeof(BitWord); }
 };
 
+static inline size_t capacity_in_bytes(const BitVector &X) {
+  return X.getMemorySize();
+}
+
 } // End llvm namespace
 
 namespace std {




More information about the llvm-commits mailing list