Merge pull request #1426 from Frangwhuf/MaskType

patch around non-exported return type
This commit is contained in:
Frang 2023-01-09 09:49:07 -05:00 committed by GitHub
commit a91111183f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 10 deletions

View File

@ -177,15 +177,15 @@ extract(int low_bit, int size) const {
if (b + size < num_bits_per_word) { if (b + size < num_bits_per_word) {
// The whole thing fits within one word of the array. // The whole thing fits within one word of the array.
return get_word(w).extract(b, size); return get_word_internal(w).extract(b, size);
} else { } else {
// We have to split it across two words. // We have to split it across two words.
int num_lower_bits = num_bits_per_word - b; int num_lower_bits = num_bits_per_word - b;
int num_higher_bits = size - num_lower_bits; int num_higher_bits = size - num_lower_bits;
return get_word(w).extract(b, num_lower_bits) | return get_word_internal(w).extract(b, num_lower_bits) |
(get_word(w + 1).extract(0, num_higher_bits) << num_lower_bits); (get_word_internal(w + 1).extract(0, num_higher_bits) << num_lower_bits);
} }
} }
@ -241,17 +241,24 @@ get_num_words() const {
* get_num_words(), but the return value beyond get_num_words() will always be * get_num_words(), but the return value beyond get_num_words() will always be
* the same. * the same.
*/ */
INLINE BitArray::MaskType BitArray:: INLINE BitArray::WordType BitArray::
get_word(size_t n) const { get_word(size_t n) const {
return get_word_internal(n).get_word();
}
/**
* Internal implementation of get_word that returns MaskType.
*/
INLINE BitArray::MaskType BitArray::
get_word_internal(size_t n) const {
nassertr(n >= 0, MaskType::all_off()); nassertr(n >= 0, MaskType::all_off());
if (n < get_num_words()) { if (n < get_num_words()) {
return _array[n]; return _array[n];
} }
if (_highest_bits) { if (_highest_bits) {
return MaskType::all_on(); return MaskType::all_on();
} else {
return MaskType::all_off();
} }
return MaskType::all_off();
} }
/** /**

View File

@ -103,7 +103,7 @@ has_any_of(int low_bit, int size) const {
} }
if (b + size <= num_bits_per_word) { if (b + size <= num_bits_per_word) {
// The whole thing fits within one word of the array. // The whole thing fits within one word of the array.
return get_word(w).has_any_of(b, size); return get_word_internal(w).has_any_of(b, size);
} }
int num_high_bits = num_bits_per_word - b; int num_high_bits = num_bits_per_word - b;
@ -156,7 +156,7 @@ has_all_of(int low_bit, int size) const {
} }
if (b + size <= num_bits_per_word) { if (b + size <= num_bits_per_word) {
// The whole thing fits within one word of the array. // The whole thing fits within one word of the array.
return get_word(w).has_all_of(b, size); return get_word_internal(w).has_all_of(b, size);
} }
int num_high_bits = num_bits_per_word - b; int num_high_bits = num_bits_per_word - b;
@ -588,7 +588,7 @@ compare_to(const BitArray &other) const {
// Compare from highest-order to lowest-order word. // Compare from highest-order to lowest-order word.
for (int i = num_words - 1; i >= 0; --i) { for (int i = num_words - 1; i >= 0; --i) {
int compare = get_word(i).compare_to(other.get_word(i)); int compare = get_word_internal(i).compare_to(other.get_word_internal(i));
if (compare != 0) { if (compare != 0) {
return compare; return compare;
} }

View File

@ -87,7 +87,7 @@ PUBLISHED:
int get_next_higher_different_bit(int low_bit) const; int get_next_higher_different_bit(int low_bit) const;
INLINE size_t get_num_words() const; INLINE size_t get_num_words() const;
INLINE MaskType get_word(size_t n) const; INLINE WordType get_word(size_t n) const;
INLINE void set_word(size_t n, WordType value); INLINE void set_word(size_t n, WordType value);
void invert_in_place(); void invert_in_place();
@ -136,6 +136,7 @@ public:
void generate_hash(ChecksumHashGenerator &hashgen) const; void generate_hash(ChecksumHashGenerator &hashgen) const;
private: private:
INLINE MaskType get_word_internal(size_t n) const;
INLINE void copy_on_write(); INLINE void copy_on_write();
void ensure_has_word(int n); void ensure_has_word(int n);
void normalize(); void normalize();