Skip to content

Commit

Permalink
Convert to size_t and formatting
Browse files Browse the repository at this point in the history
Signed-off-by: banipreetr <[email protected]>
  • Loading branch information
banipreetr committed Oct 9, 2023
1 parent bba56b6 commit 7a7c8b2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
16 changes: 10 additions & 6 deletions src/groups/mwc/mwcst/mwcst_printutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ const char* timeIntervalNsHelper(bsls::Types::Int64* num,
}

*num = ns / div;
*remainder = (int)bsl::floor(((double)(ns - *num * div) / static_cast<double>(div)) *
bsl::pow(10.0, precision));
*remainder = (int)bsl::floor(
((double)(ns - *num * div) / static_cast<double>(div)) *
bsl::pow(10.0, precision));
return TIME_INTERVAL_NS_UNITS[level];
}

Expand Down Expand Up @@ -116,8 +117,9 @@ const char* memoryHelper(bsls::Types::Int64* num,

bsls::Types::Int64 div = (((bsls::Types::Int64)1) << shift);
*num = bytes >> shift;
*remainder = (int)bsl::floor((((double)(bytes - (*num << shift)) / static_cast<double>(div)) *
bsl::pow(10.0, precision)));
*remainder = (int)bsl::floor(
(((double)(bytes - (*num << shift)) / static_cast<double>(div)) *
bsl::pow(10.0, precision)));

if (negative) {
*num = -*num;
Expand Down Expand Up @@ -322,7 +324,8 @@ int PrintUtil::printedMemoryLength(bsls::Types::Int64 bytes, int precision)
int remainder = 0;
const char* unit = memoryHelper(&value, &remainder, bytes, precision);

int ret = printedValueLength(value) + static_cast<int>(bsl::strlen(unit)) + 1;
int ret = printedValueLength(value) + static_cast<int>(bsl::strlen(unit)) +
1;
if (unit != MEMORY_UNITS[0] && precision > 0) {
ret += 1 + precision;
}
Expand Down Expand Up @@ -367,7 +370,8 @@ int PrintUtil::printedTimeIntervalNsLength(bsls::Types::Int64 timeIntervalNs,
const char* unit =
timeIntervalNsHelper(&value, &remainder, timeIntervalNs, precision);

int ret = printedValueLength(value) + static_cast<int>(bsl::strlen(unit)) + 1;
int ret = printedValueLength(value) + static_cast<int>(bsl::strlen(unit)) +
1;
if (unit != TIME_INTERVAL_NS_UNITS[0]) {
ret += 1 + precision;
}
Expand Down
24 changes: 14 additions & 10 deletions src/groups/mwc/mwcst/mwcst_statutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ StatUtil::incrementRate(const StatValue& value,
const StatValue::SnapshotLocation& firstSnapshot,
const StatValue::SnapshotLocation& secondSnapshot)
{
double diff = static_cast<double>(value.snapshot(secondSnapshot).increments() -
value.snapshot(firstSnapshot).increments());
double diff = static_cast<double>(
value.snapshot(secondSnapshot).increments() -
value.snapshot(firstSnapshot).increments());

double divisor = firstSnapshot.index() - secondSnapshot.index();
for (int i = 0; i < firstSnapshot.level(); ++i) {
Expand All @@ -86,8 +87,9 @@ double StatUtil::incrementsPerSecond(
const StatValue::SnapshotLocation& firstSnapshot,
const StatValue::SnapshotLocation& secondSnapshot)
{
double diff = static_cast<double>(value.snapshot(secondSnapshot).increments() -
value.snapshot(firstSnapshot).increments());
double diff = static_cast<double>(
value.snapshot(secondSnapshot).increments() -
value.snapshot(firstSnapshot).increments());

bsls::Types::Int64 duration =
value.snapshot(secondSnapshot).snapshotTime() -
Expand Down Expand Up @@ -118,8 +120,9 @@ StatUtil::decrementRate(const StatValue& value,
const StatValue::SnapshotLocation& firstSnapshot,
const StatValue::SnapshotLocation& secondSnapshot)
{
double diff = static_cast<double>(value.snapshot(secondSnapshot).decrements() -
value.snapshot(firstSnapshot).decrements());
double diff = static_cast<double>(
value.snapshot(secondSnapshot).decrements() -
value.snapshot(firstSnapshot).decrements());

double divisor = firstSnapshot.index() - secondSnapshot.index();
for (int i = 0; i < firstSnapshot.level(); ++i) {
Expand All @@ -134,8 +137,9 @@ double StatUtil::decrementsPerSecond(
const StatValue::SnapshotLocation& firstSnapshot,
const StatValue::SnapshotLocation& secondSnapshot)
{
double diff = static_cast<double>(value.snapshot(secondSnapshot).decrements() -
value.snapshot(firstSnapshot).decrements());
double diff = static_cast<double>(
value.snapshot(secondSnapshot).decrements() -
value.snapshot(firstSnapshot).decrements());

bsls::Types::Int64 duration =
value.snapshot(secondSnapshot).snapshotTime() -
Expand Down Expand Up @@ -172,7 +176,7 @@ double StatUtil::rate(const StatValue& value,
const StatValue::SnapshotLocation& secondSnapshot)
{
double diff = static_cast<double>(value.snapshot(secondSnapshot).value() -
value.snapshot(firstSnapshot).value());
value.snapshot(firstSnapshot).value());

int divisor = firstSnapshot.index() - secondSnapshot.index();
for (int i = 0; i < firstSnapshot.level(); ++i) {
Expand All @@ -188,7 +192,7 @@ StatUtil::ratePerSecond(const StatValue& value,
const StatValue::SnapshotLocation& secondSnapshot)
{
double diff = static_cast<double>(value.snapshot(secondSnapshot).value() -
value.snapshot(firstSnapshot).value());
value.snapshot(firstSnapshot).value());

bsls::Types::Int64 duration =
value.snapshot(secondSnapshot).snapshotTime() -
Expand Down
5 changes: 4 additions & 1 deletion src/groups/mwc/mwcst/mwcst_tableutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ int TableUtil::printTable(bsl::ostream& stream, const TableInfoProvider& info)
}

stream << bsl::setw(columnWidths[level][i]);
info.printHeader(stream, level, static_cast<int>(i), columnWidths[level][i]);
info.printHeader(stream,
level,
static_cast<int>(i),
columnWidths[level][i]);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/groups/mwc/mwcst/mwcst_testutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void TestUtil::hexToString(bsl::string* output, const bslstl::StringRef& input)
const char* q = bsl::lower_bound(HEX_DIGITS, HEX_DIGITS + 16, b);
BSLS_ASSERT_OPT(*q == b && "Bad hex input");

output->push_back(static_cast<char>((p - HEX_DIGITS) << 4) | static_cast<char>(q - HEX_DIGITS));
output->push_back(static_cast<char>((p - HEX_DIGITS) << 4) |
static_cast<char>(q - HEX_DIGITS));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/groups/mwc/mwctst/mwctst_testhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void TestHelper::printTestName(bslstl::StringRef value)
}

bsl::cout << "\n" << value << "\n";
long unsigned int length = value.length();
size_t length = value.length();
while (length--) {
bsl::cout << "=";
}
Expand Down

0 comments on commit 7a7c8b2

Please sign in to comment.