CircularIndex: optimize further for non-power-of-two sizes
- Improve count() for non-power-of-two sizes by handling wrap-around - Improve full() to use always use count(), which is cheaper in both scenarios nowpull/288/head
parent
1979d02027
commit
aaee8cab30
|
|
@ -28,9 +28,7 @@ public:
|
||||||
|
|
||||||
/// @returns true if full
|
/// @returns true if full
|
||||||
inline bool full() const {
|
inline bool full() const {
|
||||||
// alternative without wrap-around logic:
|
return count() == size;
|
||||||
// return tail != head && mask(tail) == mask(head);
|
|
||||||
return ((index_t)(head - tail) % (size * 2)) == size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reset the indexes to empty
|
/// Reset the indexes to empty
|
||||||
|
|
@ -67,13 +65,9 @@ public:
|
||||||
if constexpr (size_is_power2)
|
if constexpr (size_is_power2)
|
||||||
return head - tail;
|
return head - tail;
|
||||||
else {
|
else {
|
||||||
index_t i = tail;
|
return head >= tail
|
||||||
index_t c = 0;
|
? (head - tail)
|
||||||
while (i != head) {
|
: (size * 2 + head) - tail;
|
||||||
i = next(i);
|
|
||||||
++c;
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue