mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[util] Remove asserts from util::bitset
When used in kernel vs. non-kernel code the assert macros were not working as expected. Other util code does not use assert like this, so I'm just dropping it from bitset.
This commit is contained in:
@@ -2,12 +2,6 @@
|
||||
/// \file bitset.h
|
||||
/// Definition of the `bitset` template class
|
||||
|
||||
#if __has_include(<assert.h>)
|
||||
#include <assert.h>
|
||||
#else
|
||||
#define assert(...)
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace util {
|
||||
@@ -20,26 +14,27 @@ class bitset
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bool get(T i) const {
|
||||
assert(static_cast<unsigned>(i) < N);
|
||||
return bits(i) & bit(i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bitset & set(T i) {
|
||||
assert(static_cast<unsigned>(i) < N);
|
||||
bits(i) |= bit(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bitset & clear(T i) {
|
||||
assert(static_cast<unsigned>(i) < N);
|
||||
bits(i) &= ~bit(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bool operator[](T i) const { return get(i); }
|
||||
|
||||
inline bool empty() const {
|
||||
@@ -50,12 +45,15 @@ public:
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline uint64_t bit(T i) const { return (1ull << (static_cast<uint64_t>(i) & 63)); }
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline uint64_t &bits(T i) { return m_bits[static_cast<uint64_t>(i) >> 6]; }
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline uint64_t bits(T i) const { return m_bits[static_cast<uint64_t>(i) >> 6]; }
|
||||
|
||||
uint64_t m_bits[num_elems] = {0};
|
||||
@@ -85,30 +83,33 @@ public:
|
||||
constexpr explicit bitset(Args... args) : m_bits(bit_or(args...)) {}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bitset & operator=(T v) { m_bits = static_cast<uint64_t>(v); return *this; }
|
||||
|
||||
inline constexpr operator const uint64_t () const { return m_bits; }
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline constexpr bool get(T i) const {
|
||||
return m_bits & bit(i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bitset & set(T i) {
|
||||
assert(static_cast<unsigned>(i) < 64);
|
||||
m_bits |= bit(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bitset & clear(T i) {
|
||||
assert(static_cast<unsigned>(i) < 64);
|
||||
m_bits &= ~bit(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline constexpr bool operator[](T i) const { return get(i); }
|
||||
|
||||
inline constexpr bool empty() const { return m_bits == 0; }
|
||||
@@ -148,25 +149,27 @@ public:
|
||||
inline constexpr operator uint32_t () const { return m_bits; }
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline constexpr bool get(T i) const {
|
||||
return m_bits & bit(i);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bitset & set(T i) {
|
||||
assert(static_cast<unsigned>(i) < 32);
|
||||
m_bits |= bit(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bitset & clear(T i) {
|
||||
assert(static_cast<unsigned>(i) < 32);
|
||||
m_bits &= ~bit(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__attribute__ ((force_inline))
|
||||
inline bool operator[](T i) const { return get(i); }
|
||||
|
||||
inline bool empty() const { return m_bits == 0; }
|
||||
|
||||
Reference in New Issue
Block a user