Page MenuHomePhabricator

[libc++][format][5/6] Improve format_to_n.
Needs ReviewPublic

Authored by Mordante on Sun, Sep 26, 8:05 AM.


Group Reviewers
Restricted Project

Use a specialized buffer wrapper to limit the number of insertions in the
buffer. After the limit has been reached the buffer only needs to count
the number of insertions to return the buffer size required to store the
entire output.

Depends on D110498

Diff Detail

Event Timeline

Mordante requested review of this revision.Sun, Sep 26, 8:05 AM
Mordante created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptSun, Sep 26, 8:05 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Quuxplusone added inline comments.

Given that you continue incrementing __size_ even after hitting the end of __buffer_, I think it's a bit dangerous to use any type here except size_t. I recommend s/_Size/size_t/g.
I don't see any particular usefulness in continuing to store __n_ as _Size, either. formatted_size() is specced to return size_t, not iter_difference_t<anything>, so I think size_t throughout would make plenty of sense.

Mordante marked 2 inline comments as done.Sun, Sep 26, 9:15 AM
Mordante added inline comments.

Again what clang-format makes of the code.


The normal formatted_size indeed returns a size_t, but format_to_n returns

template<class Out> struct format_to_n_result {
  Out out;
  iter_difference_t<Out> size; // This is the formatted_size.

So I prefer to keep this the same type as the Standard specified.

Mordante planned changes to this revision.Sun, Sep 26, 10:00 AM
Mordante marked 2 inline comments as done.

Needs to be updated due to the removal of __put in D110495.

Mordante updated this revision to Diff 378455.Sat, Oct 9, 8:07 AM

Rebased and adjusted to changes in __put.

Mordante updated this revision to Diff 380190.Sat, Oct 16, 8:48 AM

Rebased to test with wchar_t changes.