Skip to content

Commit

Permalink
[native] Refactor Duration::toString and DataSize::toString to use fm…
Browse files Browse the repository at this point in the history
…t::format
  • Loading branch information
anandamideShakyan authored and aditi-pandit committed Dec 31, 2024
1 parent 2d2f689 commit 65d252c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* limitations under the License.
*/
#include "presto_cpp/presto_protocol/core/DataSize.h"
#include <fmt/format.h>
#include <math.h>

namespace facebook::presto::protocol {
Expand All @@ -29,16 +30,9 @@ DataSize::DataSize(const std::string& string) {
}

std::string DataSize::toString() const {
char buffer[32];
snprintf(
buffer,
sizeof(buffer),
"%f%s",
round(value_ * 100.0) / 100.0,
dataUnitToString(dataUnit_).c_str());
return std::string(buffer);
return fmt::format(
"{:f}{}", round(value_ * 100.0) / 100.0, dataUnitToString(dataUnit_));
}

double DataSize::toBytesPerDataUnit(DataUnit dataUnit) {
switch (dataUnit) {
case DataUnit::BYTE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* limitations under the License.
*/
#include "presto_cpp/presto_protocol/core/Duration.h"
#include <fmt/format.h>

namespace facebook::presto::protocol {

Expand All @@ -27,14 +28,7 @@ Duration::Duration(const std::string& duration) {
}

std::string Duration::toString() const {
char buffer[32];
snprintf(
buffer,
sizeof(buffer),
"%.2f%s",
value_,
timeUnitToString(timeUnit_).c_str());
return std::string(buffer);
return fmt::format("{:.2f}{}", value_, timeUnitToString(timeUnit_));
}

double Duration::toMillisPerTimeUnit(TimeUnit timeUnit) {
Expand Down

0 comments on commit 65d252c

Please sign in to comment.