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 committed Dec 20, 2024
1 parent 004ee32 commit 0377f99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 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,12 @@ DataSize::DataSize(const std::string& string) {
}

std::string DataSize::toString() const {
char buffer[32];
snprintf(
buffer,
sizeof(buffer),
"%f%s",
return fmt::format(
"{:f}{}",
round(value_ * 100.0) / 100.0,
dataUnitToString(dataUnit_).c_str());
return std::string(buffer);
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,11 @@ Duration::Duration(const std::string& duration) {
}

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

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

0 comments on commit 0377f99

Please sign in to comment.