This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Implement base 10 itoa functions.
AbandonedPublic

Authored by Mordante on Feb 7 2021, 10:18 AM.

Details

Reviewers
EricWF
ldionne
mclow.lists
miscco
curdeius
Group Reviewers
Restricted Project
Summary

This implements a new set of functions to convert an integral to a
string. Unlike the already available functions these can be:

  • used with all character types,
  • used with 128 bit integrals.

This implements the version for base 10, specialized versions for
base 2, 8, and 16 will be added later.

These functions perform better for numbers with a smaller amount of
digits and worse for number with a larger number of digits. The goal is
to investigate these differences later and see whether the new code can
be faster in all cases. It is also the intention to move to one set of
functions in the future. Since the format code still is a moving target
it's preferable to have two implementations at the moment.

Note: The usage of this code in the format header will be in a separate
patch.

Depends on D96057

Diff Detail

Event Timeline

Mordante created this revision.Feb 7 2021, 10:18 AM
Mordante requested review of this revision.Feb 7 2021, 10:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2021, 10:18 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Why do we need *another* integer to string conversion function in libc++?

I ran into some issues using the existing version:

  • There's no 128 bit integral support, which I'd like to have in std::format, I can add a __u128toa to fix this.
  • There's no direct support for wchar_t in std::to_chars.

As stated I think it would make sense to look at how we can make sure these new functions are getting merged into one version. But since std::format is still under development it would be easier to have separate functions.

There's no 128 bit integral support, which I'd like to have in std::format, I can add a __u128toa to fix this.

If you really want to support 128 bit integers (it's optional), I'd suggest thinking about extending to_chars

There's no direct support for wchar_t in std::to_chars.

have you looked at how to_wstring is implemented?

There's no 128 bit integral support, which I'd like to have in std::format, I can add a __u128toa to fix this.

If you really want to support 128 bit integers (it's optional), I'd suggest thinking about extending to_chars

.. and that can be done at a later date.

Mordante planned changes to this revision.Feb 9 2021, 10:03 AM

For now I'll postpone this patch, if other solutions work I'll abandon this patch. Else I'll have more concrete details why I want to use this solution.

Mordante abandoned this revision.May 7 2023, 9:41 AM

For now I'll postpone this patch, if other solutions work I'll abandon this patch. Else I'll have more concrete details why I want to use this solution.

This patch is no longer needed.

Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2023, 9:41 AM