/// Sample counts accumulate using saturating arithmetic, to avoid wrapping
/// around unsigned integers.
void addSamples(uint64_t S) {
- if (NumSamples <= std::numeric_limits<uint64_t>::max() - S)
- NumSamples += S;
- else
- NumSamples = std::numeric_limits<uint64_t>::max();
+ NumSamples = SaturatingAdd(NumSamples, S);
}
/// Add called function \p F with samples \p S.
/// around unsigned integers.
void addCalledTarget(StringRef F, uint64_t S) {
uint64_t &TargetSamples = CallTargets[F];
- if (TargetSamples <= std::numeric_limits<uint64_t>::max() - S)
- TargetSamples += S;
- else
- TargetSamples = std::numeric_limits<uint64_t>::max();
+ TargetSamples = SaturatingAdd(TargetSamples, S);
}
/// Return true if this sample record contains function calls.