Skip to content

Commit

Permalink
provide constexpr constructor for Sampler
Browse files Browse the repository at this point in the history
Constexpr constructor lets us use Sampler in TLS variable in cleaner
way.
  • Loading branch information
alk committed Aug 6, 2018
1 parent 1fb543c commit 467502e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class SamplerTest;

class PERFTOOLS_DLL_DECL Sampler {
public:
constexpr Sampler() {}

// Initialize this sampler.
void Init(uint64_t seed);

Expand Down Expand Up @@ -144,13 +146,13 @@ class PERFTOOLS_DLL_DECL Sampler {
//
// Always non-negative with only very brief exceptions (see
// DecrementFast{,Finish}, so casting to size_t is ok.
ssize_t bytes_until_sample_;
uint64_t rnd_; // Cheap random number generator
bool initialized_;

private:
friend class SamplerTest;
bool RecordAllocationSlow(size_t k);

ssize_t bytes_until_sample_{};
uint64_t rnd_{}; // Cheap random number generator
bool initialized_{};
};

inline bool Sampler::RecordAllocation(size_t k) {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/sampler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ double StandardDeviationsErrorInSample(
}

TEST(Sampler, LargeAndSmallAllocs_CombinedTest) {
tcmalloc::Sampler sampler{0, 0, false};
tcmalloc::Sampler sampler;
sampler.Init(1);
int counter_big = 0;
int counter_small = 0;
Expand Down

0 comments on commit 467502e

Please sign in to comment.