microsoft / microsoft/STL

<sstream>: Change the underlying buffer of basic_stringbuf to basic_string

Open
#938 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

vNext
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

See: https://github.com/microsoft/STL/pull/919#issuecomment-650688421

The underlying buffer of basic_stringbuf is simply an array, which makes implementing P0408R7 hard.

When there's an rvalue of basic_string received, we cannot simply replace the current buffer with the string buffer:

  • basic_string uses SSO (small string optimization). When it is in small mode, the string should be copied to the current buffer;
  • In readonly mode, basic_stringbuf doesn't recognize the reserved space of the string, which means we should copy the string non-conditionally.

When we want the basic_string from an rvalue of basic_stringbuf, we cannot simply construct a basic_string from the current buffer:

  • The current buffer is not zero-terminated. When the buffer is already full, we should copy the buffer to a basic_string;
  • It loses SSO, because basic_stringbuf doesn't uses SSO.

We could see that the current implementation will cause a lot of copying. I think it should be fixed in vNext.

vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the basic_stringbuf implementation and the linked P0408R7 discussion. Review how rvalue basic_string and basic_stringbuf cases interact with SSO, termination, reserved space, and readonly mode. A contribution cannot be accepted until the vNext branch is available, and completion would require a design that avoids the described copying while preserving compatibility requirements.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.