From 253c92969160b1753c0acda23a7a0cab029e056b Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Mon, 16 Nov 2015 04:02:36 +0000 Subject: [PATCH] [ADT] Make capacity_in_bytes support BitVector. NFC. This makes it a bit easier to replace instances of vector with BitVector. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253180 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/BitVector.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h index f58dd7356c7..ad00d51f99e 100644 --- a/include/llvm/ADT/BitVector.h +++ b/include/llvm/ADT/BitVector.h @@ -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 { -- 2.34.1