-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @anandamideShakyan
sizeof(buffer), | ||
"%.2f%s", | ||
return fmt::format( | ||
"{:-f}{}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use .2 in the formating here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
sizeof(buffer), | ||
"%f%s", | ||
return fmt::format( | ||
"{:-f}{}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "-" needed ? Think its the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@czentgr suggested me to use {:-f} citing : https://fmt.dev/10.2.0/syntax.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anandamideShakyan : Agree with the use of {:-f} syntax. As per the examples in https://fmt.dev/10.2.0/syntax.html#format-examples, the leading "-" is not needed. It is the default. So I was suggesting that we can skip that sign.
sizeof(buffer), | ||
"%.2f%s", | ||
return fmt::format( | ||
"{:-f}{}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "-" needed here ? It is the default.
@anandamideShakyan : Please merge your commits and use the same commit message as the PR title. https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards |
4815af0
to
d12b318
Compare
2cb3281
to
0377f99
Compare
Description
Refactored the Duration::toString and DataSize::toString methods to replace the use of snprintf with fmt::format. This change modernizes the codebase, eliminates the need for manual buffer management, and ensures safer and more readable formatting operations.
Motivation and Context
Refactored to align with modern C++ practices, improving safety, readability, and maintainability. fmt::format eliminates manual buffer management and the risks of buffer overflows inherent in snprintf.
Impact
Simplifies the code, reduces error-prone logic, and aligns with modern C++ standards. The output remains consistent with the original implementation, with minimal performance impact and improved maintainability.
Contributor checklist