Repository: google/benchmark
File: include/benchmark/benchmark.h (C/C++)

Code before:
    }
    return max_iterations - total_iterations_ + batch_leftover_;
  }

  BENCHMARK_ALWAYS_INLINE
  std::string name() const { return name_; }

 private:
  // items we expect on the first cache line (ie 64 bytes of the struct)
  // When total_iterations_ is 0, KeepRunning() and friends will return false.
  // May be larger than max_iterations.
  IterationCount total_iterations_;

  // When using KeepRunningBatch(), batch_leftover_ holds the number of
  // iterations beyond max_iters that were run. Used to track
  // completed_iterations_ accurately.
  IterationCount batch_leftover_;

 public:
  const IterationCount max_iterations;

 private:
  bool started_;
  bool finished_;
  bool skipped_;
  bool skip_is_error_;

  // items we don't need on the first cache line
  std::vector<int64_t> range_;

  int64_t complexity_n_;

 public:
  // Container for user-defined counters.
  UserCounters counters;

 private:
  State(std::string name, IterationCount max_iters,
        const std::vector<int64_t>& ranges, int thread_i, int n_threads,
        internal::ThreadTimer* timer, internal::ThreadManager* manager,
        internal::PerfCountersMeasurement* perf_counters_measurement);

  void StartKeepRunning();
  // Implementation of KeepRunning() and KeepRunningBatch().
  // is_batch must be true unless n is 1.
  bool KeepRunningInternal(IterationCount n, bool is_batch);
  void FinishKeepRunning();

  const std::string name_;
  const int thread_index_;
  const int threads_;

Review comment (refactor):
my first draft kept the name(s) as `error_ocurred` but then i had a bunch of `if skipped || error` statements.  it was much cleaner when i refactored to make `error` a subset of `skipped`

Code after:
  int64_t range(std::size_t pos = 0) const {
    assert(range_.size() > pos);
    return range_[pos];
  }

  BENCHMARK_DEPRECATED_MSG("use 'range(0)' instead")
  int64_t range_x() const { return range(0); }

  BENCHMARK_DEPRECATED_MSG("use 'range(1)' instead")
  int64_t range_y() const { return range(1); }

  // Number of threads concurrently executing the benchmark.
  BENCHMARK_ALWAYS_INLINE
  int threads() const { return threads_; }

  // Index of the executing thread. Values from [0, threads).
  BENCHMARK_ALWAYS_INLINE
  int thread_index() const { return thread_index_; }

  BENCHMARK_ALWAYS_INLINE
  IterationCount iterations() const {
    if (BENCHMARK_BUILTIN_EXPECT(!started_, false)) {
      return 0;
    }
    return max_iterations - total_iterations_ + batch_leftover_;
  }

  BENCHMARK_ALWAYS_INLINE
  std::string name() const { return name_; }

 private:
  // items we expect on the first cache line (ie 64 bytes of the struct)
  // When total_iterations_ is 0, KeepRunning() and friends will return false.
  // May be larger than max_iterations.
  IterationCount total_iterations_;

  // When using KeepRunningBatch(), batch_leftover_ holds the number of
  // iterations beyond max_iters that were run. Used to track
  // completed_iterations_ accurately.
  IterationCount batch_leftover_;

 public:
  const IterationCount max_iterations;

 private:
  bool started_;
  bool finished_;
  internal::Skipped skipped_;

  // items we don't need on the first cache line
  std::vector<int64_t> range_;