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

Decimal as String conversion functions #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mhoferica
Copy link

Preliminary feedback. Not sure how you want to utilize templates for these functions and if the deliminator or terminator is necessary.

Ex.
//template
char a_terminator = '\0'

Copy link
Owner

@saleyn saleyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • What's the point of passing integer and unsigned integer arguments by reference in to_string and other functions?
  • Please format all function names and variable names in boost notation style (i.e. function_name() instead of functionName() and int var_name instead of int varName).
  • in to_string() please don't use snprintf() - it's very slow. You can use utxx::itoa() instead.
  • Your other functions use strcpy and strlen, however, it's not guaranteed that the string will have '\0' terminator. Especially if the a_terminator is passed as something other than '\0'.

@mhoferica
Copy link
Author

mhoferica commented Jan 5, 2021

What's the point of passing integer and unsigned integer arguments by reference in to_string and other functions?
In my test harness it improved performance as the values are not copied

Please format all function names and variable names in boost notation style (i.e. function_name() instead of functionName() and int var_name instead of int varName)
Yes, I missed the var names, will correct

in to_string() please don't use snprintf() - it's very slow. You can use utxx::itoa() instead
_In my test harness I ran with snprintf and it was a bit faster compared to existing similar function that converted from double to string, of course it isn't an exact comparison but the point is the function overall is still fast, I will use utxx::itoa() regardless and compare results.

Your other functions use strcpy and strlen, however, it's not guaranteed that the string will have '\0' terminator. Especially if the a_terminator is passed as something other than '\0'.
Ok, I understand the case of the terminator, will incorporate.

@saleyn
Copy link
Owner

saleyn commented Jan 5, 2021

In my test harness it improved performance as the values are not copied

It depends on what you were measuring. If the cost measure is memory usage, pass by copy is less efficient, and if the cost measure is performance, then using a reference involves an extra dereferencing operation, which is always slower. gcc has an option -fipa-sra (https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html), which converts const refs to a value by copy for primitive types. But what's the point of writing more code (i.e. const& and relying on the compiler to remove that), rather than passing primitive types by value?

@mhoferica
Copy link
Author

Understood. Valid point, I'll make the correction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants