Summary:
Address multiple -Werror=sign-compare issues exposed when building
tao with gcc-4.9.
In most of these changes I've changed the type of the index in
a for-loop from int to size_t. The important thing is to use
an unsigned type when the limit is also unsigned. I choose size_t
because the general recommendation (when writing portable code)
to avoid size-tied types like uint32_t and uint64_t unless you
have a very good reason to require them.
Test Plan:
Run this and note there are fewer errors than before:
fbconfig --platform-all=gcc-4.9-glibc-2.20 tao/server && fbmake dbgo
Reviewed By: andrei.alexandrescu@fb.com
Subscribers: trunkagent, net-systems@, folly-diffs@
FB internal diff:
D1766651
Tasks:
5941250
Signature: t1:
1766651:
1420594537:
56ef53ca233e1649469db9570942c1d5dd47cf6d
/* Remove all data points from the histogram */
void clear() {
- for (int i = 0; i < buckets_.getNumBuckets(); i++) {
+ for (unsigned int i = 0; i < buckets_.getNumBuckets(); i++) {
buckets_.getByIndex(i).clear();
}
}
throw std::invalid_argument("Cannot subtract input histogram.");
}
- for (int i = 0; i < buckets_.getNumBuckets(); i++) {
+ for (unsigned int i = 0; i < buckets_.getNumBuckets(); i++) {
buckets_.getByIndex(i) -= hist.buckets_.getByIndex(i);
}
}
throw std::invalid_argument("Cannot merge from input histogram.");
}
- for (int i = 0; i < buckets_.getNumBuckets(); i++) {
+ for (unsigned int i = 0; i < buckets_.getNumBuckets(); i++) {
buckets_.getByIndex(i) += hist.buckets_.getByIndex(i);
}
}
throw std::invalid_argument("Cannot copy from input histogram.");
}
- for (int i = 0; i < buckets_.getNumBuckets(); i++) {
+ for (unsigned int i = 0; i < buckets_.getNumBuckets(); i++) {
buckets_.getByIndex(i) = hist.buckets_.getByIndex(i);
}
}
CHECK(levelDurations);
levels_.reserve(nLevels);
- for (int i = 0; i < nLevels; ++i) {
+ for (size_t i = 0; i < nLevels; ++i) {
if (levelDurations[i] == TT(0)) {
CHECK_EQ(i, nLevels - 1);
} else if (i > 0) {
template <typename VT, typename TT>
void MultiLevelTimeSeries<VT, TT>::update(TimeType now) {
flush();
- for (int i = 0; i < levels_.size(); ++i) {
+ for (size_t i = 0; i < levels_.size(); ++i) {
levels_[i].update(now);
}
}
void MultiLevelTimeSeries<VT, TT>::flush() {
// update all the underlying levels
if (cachedCount_ > 0) {
- for (int i = 0; i < levels_.size(); ++i) {
+ for (size_t i = 0; i < levels_.size(); ++i) {
levels_[i].addValueAggregated(cachedTime_, cachedSum_, cachedCount_);
}
cachedCount_ = 0;
ReturnType TimeseriesHistogram<T, TT, C>::avg(int level) const {
ValueType total = ValueType();
int64_t nsamples = 0;
- for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
+ for (unsigned int b = 0; b < buckets_.getNumBuckets(); ++b) {
const auto& levelObj = buckets_.getByIndex(b).getLevel(level);
total += levelObj.sum();
nsamples += levelObj.count();
TimeType end) const {
ValueType total = ValueType();
int64_t nsamples = 0;
- for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
+ for (unsigned int b = 0; b < buckets_.getNumBuckets(); ++b) {
const auto& levelObj = buckets_.getByIndex(b).getLevel(start, end);
total += levelObj.sum(start, end);
nsamples += levelObj.count(start, end);
TimeType end) const {
ValueType total = ValueType();
TimeType elapsed(0);
- for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
+ for (unsigned int b = 0; b < buckets_.getNumBuckets(); ++b) {
const auto& level = buckets_.getByIndex(b).getLevel(start);
total += level.sum(start, end);
elapsed = std::max(elapsed, level.elapsed(start, end));
T TimeseriesHistogram<T, TT, C>::rate(int level) const {
ValueType total = ValueType();
TimeType elapsed(0);
- for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
+ for (unsigned int b = 0; b < buckets_.getNumBuckets(); ++b) {
const auto& levelObj = buckets_.getByIndex(b).getLevel(level);
total += levelObj.sum();
elapsed = std::max(elapsed, levelObj.elapsed());
/* Total count of values at the given timeseries level (all buckets). */
int64_t count(int level) const {
int64_t total = 0;
- for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
+ for (unsigned int b = 0; b < buckets_.getNumBuckets(); ++b) {
total += buckets_.getByIndex(b).count(level);
}
return total;
/* Total count of values added during the given interval (all buckets). */
int64_t count(TimeType start, TimeType end) const {
int64_t total = 0;
- for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
+ for (unsigned int b = 0; b < buckets_.getNumBuckets(); ++b) {
total += buckets_.getByIndex(b).count(start, end);
}
return total;
/* Total sum of values at the given timeseries level (all buckets). */
ValueType sum(int level) const {
ValueType total = ValueType();
- for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
+ for (unsigned int b = 0; b < buckets_.getNumBuckets(); ++b) {
total += buckets_.getByIndex(b).sum(level);
}
return total;
/* Total sum of values added during the given interval (all buckets). */
ValueType sum(TimeType start, TimeType end) const {
ValueType total = ValueType();
- for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
+ for (unsigned int b = 0; b < buckets_.getNumBuckets(); ++b) {
total += buckets_.getByIndex(b).sum(start, end);
}
return total;