Rename shadowing local variables in various stats objects
authorMatt Dordal <mnd@fb.com>
Wed, 3 Sep 2014 23:47:14 +0000 (16:47 -0700)
committerSara Golemon <sgolemon@fb.com>
Tue, 9 Sep 2014 21:22:23 +0000 (14:22 -0700)
Summary:
The GCC shadow variable detector is quite zealous in warning about
shadowed members. Here, we have local variables that share the name
of member functions. Rename them so that -Wshadow doesn't complain.

Test Plan:
It didn't build, and now it does.

`fbconfig -r folly && fbmake runtests`

Reviewed By: njormrod@fb.com

Subscribers: fbcode-common-diffs@, njormrod

FB internal diff: D1534033

folly/stats/BucketedTimeSeries-defs.h
folly/stats/BucketedTimeSeries.h
folly/stats/MultiLevelTimeSeries-defs.h
folly/stats/TimeseriesHistogram-defs.h

index c2ada60..aa7786b 100644 (file)
 namespace folly {
 
 template <typename VT, typename TT>
-BucketedTimeSeries<VT, TT>::BucketedTimeSeries(size_t numBuckets,
-                                               TimeType duration)
+BucketedTimeSeries<VT, TT>::BucketedTimeSeries(size_t nBuckets,
+                                               TimeType maxDuration)
   : firstTime_(1),
     latestTime_(0),
-    duration_(duration) {
+    duration_(maxDuration) {
   // For tracking all-time data we only use total_, and don't need to bother
   // with buckets_
   if (!isAllTime()) {
-    // Round numBuckets down to duration_.count().
+    // Round nBuckets down to duration_.count().
     //
     // There is no point in having more buckets than our timestamp
     // granularity: otherwise we would have buckets that could never be used.
-    if (numBuckets > duration_.count()) {
-      numBuckets = duration_.count();
+    if (nBuckets > duration_.count()) {
+      nBuckets = duration_.count();
     }
 
-    buckets_.resize(numBuckets, Bucket());
+    buckets_.resize(nBuckets, Bucket());
   }
 }
 
@@ -57,7 +57,7 @@ bool BucketedTimeSeries<VT, TT>::addValue(TimeType now,
 
 template <typename VT, typename TT>
 bool BucketedTimeSeries<VT, TT>::addValueAggregated(TimeType now,
-                                                    const ValueType& sum,
+                                                    const ValueType& total,
                                                     int64_t nsamples) {
   if (isAllTime()) {
     if (UNLIKELY(empty())) {
@@ -68,7 +68,7 @@ bool BucketedTimeSeries<VT, TT>::addValueAggregated(TimeType now,
     } else if (now < firstTime_) {
       firstTime_ = now;
     }
-    total_.add(sum, nsamples);
+    total_.add(total, nsamples);
     return true;
   }
 
@@ -93,8 +93,8 @@ bool BucketedTimeSeries<VT, TT>::addValueAggregated(TimeType now,
     bucketIdx = getBucketIdx(now);
   }
 
-  total_.add(sum, nsamples);
-  buckets_[bucketIdx].add(sum, nsamples);
+  total_.add(total, nsamples);
+  buckets_[bucketIdx].add(total, nsamples);
   return true;
 }
 
@@ -239,52 +239,52 @@ TT BucketedTimeSeries<VT, TT>::elapsed(TimeType start, TimeType end) const {
 
 template <typename VT, typename TT>
 VT BucketedTimeSeries<VT, TT>::sum(TimeType start, TimeType end) const {
-  ValueType sum = ValueType();
+  ValueType total = ValueType();
   forEachBucket(start, end, [&](const Bucket& bucket,
                                 TimeType bucketStart,
                                 TimeType nextBucketStart) -> bool {
-    sum += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
+    total += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
                              bucket.sum);
     return true;
   });
 
-  return sum;
+  return total;
 }
 
 template <typename VT, typename TT>
 uint64_t BucketedTimeSeries<VT, TT>::count(TimeType start, TimeType end) const {
-  uint64_t count = 0;
+  uint64_t sample_count = 0;
   forEachBucket(start, end, [&](const Bucket& bucket,
                                 TimeType bucketStart,
                                 TimeType nextBucketStart) -> bool {
-    count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
+    sample_count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
                                bucket.count);
     return true;
   });
 
-  return count;
+  return sample_count;
 }
 
 template <typename VT, typename TT>
 template <typename ReturnType>
 ReturnType BucketedTimeSeries<VT, TT>::avg(TimeType start, TimeType end) const {
-  ValueType sum = ValueType();
-  uint64_t count = 0;
+  ValueType total = ValueType();
+  uint64_t sample_count = 0;
   forEachBucket(start, end, [&](const Bucket& bucket,
                                 TimeType bucketStart,
                                 TimeType nextBucketStart) -> bool {
-    sum += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
+    total += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
                              bucket.sum);
-    count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
+    sample_count += this->rangeAdjust(bucketStart, nextBucketStart, start, end,
                                bucket.count);
     return true;
   });
 
-  if (count == 0) {
+  if (sample_count == 0) {
     return ReturnType(0);
   }
 
-  return detail::avgHelper<ReturnType>(sum, count);
+  return detail::avgHelper<ReturnType>(total, sample_count);
 }
 
 /*
index 912e719..e613e9f 100644 (file)
@@ -382,9 +382,9 @@ class BucketedTimeSeries {
 
  private:
   template <typename ReturnType=double, typename Interval=TimeType>
-  ReturnType rateHelper(ReturnType numerator, TimeType elapsed) const {
+  ReturnType rateHelper(ReturnType numerator, TimeType elapsedTime) const {
     return detail::rateHelper<ReturnType, TimeType, Interval>(numerator,
-                                                              elapsed);
+                                                              elapsedTime);
   }
 
   TimeType getEarliestTimeNonEmpty() const;
index 028f764..cb119d8 100644 (file)
@@ -23,23 +23,23 @@ namespace folly {
 
 template <typename VT, typename TT>
 MultiLevelTimeSeries<VT, TT>::MultiLevelTimeSeries(
-  size_t numBuckets,
-  size_t numLevels,
+  size_t nBuckets,
+  size_t nLevels,
   const TimeType levelDurations[])
     : cachedTime_(0),
       cachedSum_(0),
       cachedCount_(0) {
-    CHECK_GT(numLevels, 0);
+    CHECK_GT(nLevels, 0);
     CHECK(levelDurations);
 
-    levels_.reserve(numLevels);
-    for (int i = 0; i < numLevels; ++i) {
+    levels_.reserve(nLevels);
+    for (int i = 0; i < nLevels; ++i) {
       if (levelDurations[i] == TT(0)) {
-        CHECK_EQ(i, numLevels - 1);
+        CHECK_EQ(i, nLevels - 1);
       } else if (i > 0) {
         CHECK(levelDurations[i-1] < levelDurations[i]);
       }
-      levels_.emplace_back(numBuckets, levelDurations[i]);
+      levels_.emplace_back(nBuckets, levelDurations[i]);
     }
 }
 
@@ -58,13 +58,13 @@ void MultiLevelTimeSeries<VT, TT>::addValue(TimeType now,
 
 template <typename VT, typename TT>
 void MultiLevelTimeSeries<VT, TT>::addValueAggregated(TimeType now,
-                                                      const ValueType& sum,
+                                                      const ValueType& total,
                                                       int64_t nsamples) {
   if (cachedTime_ != now) {
     flush();
     cachedTime_ = now;
   }
-  cachedSum_ += sum;
+  cachedSum_ += total;
   cachedCount_ += nsamples;
 }
 
index 2ee4b06..094cdde 100644 (file)
@@ -28,13 +28,13 @@ template <class T, class TT, class C>
 template <typename ReturnType>
 ReturnType TimeseriesHistogram<T, TT, C>::avg(int level) const {
   ValueType total = ValueType();
-  int64_t count = 0;
+  int64_t nsamples = 0;
   for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
     const auto& levelObj = buckets_.getByIndex(b).getLevel(level);
     total += levelObj.sum();
-    count += levelObj.count();
+    nsamples += levelObj.count();
   }
-  return folly::detail::avgHelper<ReturnType>(total, count);
+  return folly::detail::avgHelper<ReturnType>(total, nsamples);
 }
 
 template <class T, class TT, class C>
@@ -42,13 +42,13 @@ template <typename ReturnType>
 ReturnType TimeseriesHistogram<T, TT, C>::avg(TimeType start,
                                               TimeType end) const {
   ValueType total = ValueType();
-  int64_t count = 0;
+  int64_t nsamples = 0;
   for (int b = 0; b < buckets_.getNumBuckets(); ++b) {
     const auto& levelObj = buckets_.getByIndex(b).getLevel(start, end);
     total += levelObj.sum(start, end);
-    count += levelObj.count(start, end);
+    nsamples += levelObj.count(start, end);
   }
-  return folly::detail::avgHelper<ReturnType>(total, count);
+  return folly::detail::avgHelper<ReturnType>(total, nsamples);
 }
 
 template <class T, class TT, class C>