From 8b5bb34a260f0ae2864f3ac6e927968aa1f2f213 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 12 Jun 2010 13:58:09 +0000 Subject: [PATCH] 2010-06-12 Tatsuhiro Tsujikawa Renamed member variables * src/SpeedCalc.cc * src/SpeedCalc.h --- ChangeLog | 6 ++++++ src/SpeedCalc.cc | 54 +++++++++++++++++++++++++----------------------- src/SpeedCalc.h | 18 ++++++++-------- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 454cb225..0fb88d0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-06-12 Tatsuhiro Tsujikawa + + Renamed member variables + * src/SpeedCalc.cc + * src/SpeedCalc.h + 2010-06-12 Tatsuhiro Tsujikawa Renamed member variables in SegmentMan diff --git a/src/SpeedCalc.cc b/src/SpeedCalc.cc index 4fcad661..17ced794 100644 --- a/src/SpeedCalc.cc +++ b/src/SpeedCalc.cc @@ -43,41 +43,42 @@ namespace aria2 { #define CHANGE_INTERVAL_SEC 15 -SpeedCalc::SpeedCalc():sw(0), maxSpeed(0), prevSpeed(0), accumulatedLength(0), - nextInterval(CHANGE_INTERVAL_SEC) +SpeedCalc::SpeedCalc():_sw(0), _maxSpeed(0), _prevSpeed(0), + _accumulatedLength(0), + _nextInterval(CHANGE_INTERVAL_SEC) { - std::fill(&lengthArray[0], &lengthArray[2], 0); + std::fill(&_lengthArray[0], &_lengthArray[2], 0); } void SpeedCalc::reset() { - std::fill(&lengthArray[0], &lengthArray[2], 0); - std::fill(&cpArray[0], &cpArray[2], global::wallclock); - sw = 0; - maxSpeed = 0; - prevSpeed = 0; - start = global::wallclock; - accumulatedLength = 0; - nextInterval = CHANGE_INTERVAL_SEC; + std::fill(&_lengthArray[0], &_lengthArray[2], 0); + std::fill(&_cpArray[0], &_cpArray[2], global::wallclock); + _sw = 0; + _maxSpeed = 0; + _prevSpeed = 0; + _start = global::wallclock; + _accumulatedLength = 0; + _nextInterval = CHANGE_INTERVAL_SEC; } unsigned int SpeedCalc::calculateSpeed() { - int64_t milliElapsed = cpArray[sw].differenceInMillis(global::wallclock); + int64_t milliElapsed = _cpArray[_sw].differenceInMillis(global::wallclock); if(milliElapsed) { - unsigned int speed = lengthArray[sw]*1000/milliElapsed; - prevSpeed = speed; - maxSpeed = std::max(speed, maxSpeed); + unsigned int speed = _lengthArray[_sw]*1000/milliElapsed; + _prevSpeed = speed; + _maxSpeed = std::max(speed, _maxSpeed); if(isIntervalOver(milliElapsed)) { changeSw(); } return speed; } else { - return prevSpeed; + return _prevSpeed; } } void SpeedCalc::update(size_t bytes) { - accumulatedLength += bytes; - std::transform(&lengthArray[0], &lengthArray[2], &lengthArray[0], + _accumulatedLength += bytes; + std::transform(&_lengthArray[0], &_lengthArray[2], &_lengthArray[0], std::bind1st(std::plus(), (uint64_t)bytes)); if(isIntervalOver()) { changeSw(); @@ -85,27 +86,28 @@ void SpeedCalc::update(size_t bytes) { } bool SpeedCalc::isIntervalOver() const { - return nextInterval <= cpArray[sw].difference(global::wallclock); + return _nextInterval <= _cpArray[_sw].difference(global::wallclock); } bool SpeedCalc::isIntervalOver(int64_t milliElapsed) const { - return nextInterval <= milliElapsed/1000; + return _nextInterval <= milliElapsed/1000; } void SpeedCalc::changeSw() { - lengthArray[sw] = 0; - cpArray[sw] = global::wallclock; - sw ^= 0x01; - nextInterval = cpArray[sw].difference(global::wallclock)+CHANGE_INTERVAL_SEC; + _lengthArray[_sw] = 0; + _cpArray[_sw] = global::wallclock; + _sw ^= 0x01; + _nextInterval = + _cpArray[_sw].difference(global::wallclock)+CHANGE_INTERVAL_SEC; } unsigned int SpeedCalc::calculateAvgSpeed() const { - uint64_t milliElapsed = start.differenceInMillis(global::wallclock); + uint64_t milliElapsed = _start.differenceInMillis(global::wallclock); // if milliElapsed is too small, the average speed is rubish, better return 0 if(milliElapsed > 4) { - unsigned int speed = accumulatedLength*1000/milliElapsed; + unsigned int speed = _accumulatedLength*1000/milliElapsed; return speed; } else { return 0; diff --git a/src/SpeedCalc.h b/src/SpeedCalc.h index d8fcae1f..112e02cf 100644 --- a/src/SpeedCalc.h +++ b/src/SpeedCalc.h @@ -42,14 +42,14 @@ namespace aria2 { class SpeedCalc { private: - uint64_t lengthArray[2]; - int sw; - Timer cpArray[2]; - unsigned int maxSpeed; - unsigned int prevSpeed; - Timer start; - uint64_t accumulatedLength; - time_t nextInterval; + uint64_t _lengthArray[2]; + int _sw; + Timer _cpArray[2]; + unsigned int _maxSpeed; + unsigned int _prevSpeed; + Timer _start; + uint64_t _accumulatedLength; + time_t _nextInterval; bool isIntervalOver() const; @@ -65,7 +65,7 @@ public: unsigned int calculateSpeed(); unsigned int getMaxSpeed() const { - return maxSpeed; + return _maxSpeed; } unsigned int calculateAvgSpeed() const;