summaryrefslogtreecommitdiffstats
path: root/src/build.h
diff options
context:
space:
mode:
authorPeter Kümmel <syntheticpp@gmx.net>2012-09-18 07:10:47 (GMT)
committerPeter Kümmel <syntheticpp@gmx.net>2012-09-18 07:10:47 (GMT)
commitde6ec48d80879ce9279b3e13c24787e9054d942f (patch)
tree355807f68d571dd9529d40b2a7d2e11930702acd /src/build.h
parentd95fcb0cdc816e2585ce9a65676320d71af78c7f (diff)
downloadNinja-de6ec48d80879ce9279b3e13c24787e9054d942f.zip
Ninja-de6ec48d80879ce9279b3e13c24787e9054d942f.tar.gz
Ninja-de6ec48d80879ce9279b3e13c24787e9054d942f.tar.bz2
remove some code duplication
Diffstat (limited to 'src/build.h')
-rw-r--r--src/build.h28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/build.h b/src/build.h
index 0902a4c..c94c8cc 100644
--- a/src/build.h
+++ b/src/build.h
@@ -200,31 +200,33 @@ struct BuildStatus {
/// The custom progress status format to use.
const char* progress_status_format_;
+ template<class T>
+ void snprinfRate(double rate, T buf, const char* format) const {
+ if (rate == -1) snprintf(buf, sizeof(buf), "?");
+ else snprintf(buf, sizeof(buf), format, rate);
+ }
+
struct RateInfo {
RateInfo() : rate_(-1) {}
void Restart() { stopwatch_.Restart(); }
+ double rate() { return rate_; }
void UpdateRate(int edges) {
if (edges && stopwatch_.Elapsed())
rate_ = edges / stopwatch_.Elapsed();
}
- template<class T>
- void snprinfRate(T buf, const char* format) {
- if (rate_ == -1) snprintf(buf, sizeof(buf), "?");
- else snprintf(buf, sizeof(buf), format, rate_);
- }
-
private:
- Stopwatch stopwatch_;
double rate_;
+ Stopwatch stopwatch_;
};
struct SlidingRateInfo {
- SlidingRateInfo(int n) : N(n), last_update_(-1), rate_(-1) {}
+ SlidingRateInfo(int n) : rate_(-1), N(n), last_update_(-1) {}
void Restart() { stopwatch_.Restart(); }
+ double rate() { return rate_; }
void UpdateRate(int update_hint) {
if (update_hint == last_update_)
@@ -238,18 +240,12 @@ struct BuildStatus {
rate_ = times_.size() / (times_.back() - times_.front());
}
- template<class T>
- void snprinfRate(T buf, const char* format) {
- if (rate_ == -1) snprintf(buf, sizeof(buf), "?");
- else snprintf(buf, sizeof(buf), format, rate_);
- }
-
private:
+ double rate_;
+ Stopwatch stopwatch_;
const size_t N;
std::queue<double> times_;
- Stopwatch stopwatch_;
int last_update_;
- double rate_;
};
mutable RateInfo overall_rate_;