mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-06 15:04:34 +08:00
Use boost:circular_buffer instead of QList.
QList has to store an additional pointer for each element which leads to bad space efficiency.
This commit is contained in:
parent
fc0746eb71
commit
f13c604fbe
@ -27,17 +27,21 @@
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include <QList>
|
||||
#include "speedmonitor.h"
|
||||
|
||||
SpeedMonitor::SpeedMonitor()
|
||||
: m_speedSamples(MAX_SAMPLES)
|
||||
{
|
||||
}
|
||||
|
||||
void SpeedMonitor::addSample(const SpeedSample &sample)
|
||||
{
|
||||
if (m_speedSamples.size() >= MAX_SAMPLES) {
|
||||
m_sum -= m_speedSamples.front();
|
||||
}
|
||||
|
||||
m_speedSamples.push_back(sample);
|
||||
m_sum += sample;
|
||||
if (m_speedSamples.size() > MAX_SAMPLES) {
|
||||
m_sum -= m_speedSamples.front();
|
||||
m_speedSamples.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
SpeedSampleAvg SpeedMonitor::average() const
|
||||
|
@ -30,7 +30,11 @@
|
||||
#ifndef SPEEDMONITOR_H
|
||||
#define SPEEDMONITOR_H
|
||||
|
||||
template<typename T> class QList;
|
||||
#ifndef Q_MOC_RUN
|
||||
#include <boost/circular_buffer.hpp>
|
||||
#endif
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
template<typename T>
|
||||
struct Sample
|
||||
@ -71,13 +75,15 @@ typedef Sample<qreal> SpeedSampleAvg;
|
||||
class SpeedMonitor
|
||||
{
|
||||
public:
|
||||
SpeedMonitor();
|
||||
|
||||
void addSample(const SpeedSample &sample);
|
||||
SpeedSampleAvg average() const;
|
||||
void reset();
|
||||
|
||||
private:
|
||||
static const int MAX_SAMPLES = 30;
|
||||
QList<SpeedSample> m_speedSamples;
|
||||
boost::circular_buffer<SpeedSample> m_speedSamples;
|
||||
SpeedSample m_sum;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user