diff options
Diffstat (limited to 'src/mongo/bson/ordering.h')
-rw-r--r-- | src/mongo/bson/ordering.h | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/mongo/bson/ordering.h b/src/mongo/bson/ordering.h index 1521044d468..d1178623f91 100644 --- a/src/mongo/bson/ordering.h +++ b/src/mongo/bson/ordering.h @@ -39,11 +39,12 @@ namespace mongo { * Over time we should push this up higher and higher. */ class Ordering { - unsigned bits; - Ordering(unsigned b) : bits(b) {} + uint32_t bits; + Ordering(uint32_t b) : bits(b) {} public: static constexpr size_t kMaxCompoundIndexKeys = size_t{32}; + static_assert(kMaxCompoundIndexKeys == 8 * sizeof(bits)); static Ordering allAscending() { return {0}; @@ -62,24 +63,24 @@ public: uassert(ErrorCodes::Overflow, str::stream() << "Ordering offset is out of bounds: " << i, i >= 0 && static_cast<size_t>(i) < kMaxCompoundIndexKeys); - return ((1 << i) & bits) ? -1 : 1; + return ((1u << i) & bits) ? -1 : 1; } - unsigned descending(unsigned mask) const { + uint32_t descending(uint32_t mask) const { return bits & mask; } static Ordering make(const BSONObj& obj) { - unsigned b = 0; + uint32_t b = 0; BSONObjIterator k(obj); - unsigned n = 0; + uint32_t n = 0; while (1) { BSONElement e = k.next(); if (e.eoo()) break; uassert(13103, "too many compound keys", n < kMaxCompoundIndexKeys); if (e.number() < 0) - b |= (1 << n); + b |= (1u << n); n++; } return Ordering(b); |