Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native] Refactor Duration::toString and DataSize::toString to use fmt::format #24241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
aditi-pandit marked this conversation as resolved.
Show resolved Hide resolved
#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
Loading