Optimization and cleanup

This commit is contained in:
Adam Ierymenko 2019-08-26 20:18:28 -07:00
parent 8203547cfc
commit 6f22570648
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
17 changed files with 261 additions and 266 deletions

View file

@ -43,7 +43,7 @@ private:
bool wrap;
public:
inline RingBuffer() :
ZT_ALWAYS_INLINE RingBuffer() :
begin(0),
end(0),
wrap(false)
@ -54,7 +54,7 @@ public:
/**
* @return A pointer to the underlying buffer
*/
inline T *get_buf()
ZT_ALWAYS_INLINE T *get_buf()
{
return buf + begin;
}
@ -64,7 +64,7 @@ public:
* @param n Number of elements to copy in
* @return Number of elements we copied in
*/
inline size_t produce(size_t n)
ZT_ALWAYS_INLINE size_t produce(size_t n)
{
n = std::min(n, getFree());
if (n == 0) {
@ -86,14 +86,14 @@ public:
* Fast erase, O(1).
* Merely reset the buffer pointer, doesn't erase contents
*/
inline void reset() { consume(count()); }
ZT_ALWAYS_INLINE void reset() { consume(count()); }
/**
* adjust buffer index pointer as if we copied data out
* @param n Number of elements we copied from the buffer
* @return Number of elements actually available from the buffer
*/
inline size_t consume(size_t n)
ZT_ALWAYS_INLINE size_t consume(size_t n)
{
n = std::min(n, count());
if (n == 0) {
@ -115,7 +115,7 @@ public:
* @param data Buffer that is to be written to the ring
* @param n Number of elements to write to the buffer
*/
inline size_t write(const T * data, size_t n)
ZT_ALWAYS_INLINE size_t write(const T * data, size_t n)
{
n = std::min(n, getFree());
if (n == 0) {
@ -140,7 +140,7 @@ public:
*
* @param value A single value to be placed in the buffer
*/
inline void push(const T value)
ZT_ALWAYS_INLINE void push(const T value)
{
if (count() == S) {
consume(1);
@ -156,14 +156,14 @@ public:
/**
* @return The most recently pushed element on the buffer
*/
inline T get_most_recent() { return *(buf + end); }
ZT_ALWAYS_INLINE T get_most_recent() { return *(buf + end); }
/**
* @param dest Destination buffer
* @param n Size (in terms of number of elements) of the destination buffer
* @return Number of elements read from the buffer
*/
inline size_t read(T *dest,size_t n)
ZT_ALWAYS_INLINE size_t read(T *dest,size_t n)
{
n = std::min(n, count());
if (n == 0) {
@ -188,7 +188,7 @@ public:
*
* @return The number of elements in the buffer
*/
inline size_t count()
ZT_ALWAYS_INLINE size_t count()
{
if (end == begin) {
return wrap ? S : 0;
@ -204,12 +204,12 @@ public:
/**
* @return The number of slots that are unused in the buffer
*/
inline size_t getFree() { return S - count(); }
ZT_ALWAYS_INLINE size_t getFree() { return S - count(); }
/**
* @return The arithmetic mean of the contents of the buffer
*/
inline float mean()
ZT_ALWAYS_INLINE float mean()
{
size_t iterator = begin;
float subtotal = 0;
@ -224,7 +224,7 @@ public:
/**
* @return The arithmetic mean of the most recent 'n' elements of the buffer
*/
inline float mean(size_t n)
ZT_ALWAYS_INLINE float mean(size_t n)
{
n = n < S ? n : S;
size_t iterator = begin;
@ -240,12 +240,12 @@ public:
/**
* @return The sample standard deviation of element values
*/
inline float stddev() { return sqrt(variance()); }
ZT_ALWAYS_INLINE float stddev() { return sqrt(variance()); }
/**
* @return The variance of element values
*/
inline float variance()
ZT_ALWAYS_INLINE float variance()
{
size_t iterator = begin;
float cached_mean = mean();
@ -263,7 +263,7 @@ public:
/**
* @return The number of elements of zero value
*/
inline size_t zeroCount()
ZT_ALWAYS_INLINE size_t zeroCount()
{
size_t iterator = begin;
size_t zeros = 0;
@ -281,7 +281,7 @@ public:
* @param value Value to match against in buffer
* @return The number of values held in the ring buffer which match a given value
*/
inline size_t countValue(T value)
ZT_ALWAYS_INLINE size_t countValue(T value)
{
size_t iterator = begin;
size_t cnt = 0;