`<xstring>`: `basic_string` could handle insert aliasing without allocating in some common cases
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.1k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Notably:
- Given a range of contiguous iterators we can directly determine if it aliases the string contents.
- Given a sized or forward range that will fit in available capacity, we could append and then rotate (which can't throw) into place to effect inserts even in the presence of aliasing.
- For sizeable-but-won't-fit, we could allocate the new memory, insert the new range in place, and then move (which can't throw) the pre-existing characters.
- For non-sizeable, fill the tail, either rotating if the capacity suffices or shifting into the correct places when we do allocate a new block.
Note that these are roughly in order of ease of implementation and expected improvement. The more exotic the workaround, the less improvement we can expect over the dumb "make a temporary string and then merge" strategy.
(Inspired by discussion in https://github.com/microsoft/STL/pull/2806#discussion_r918399814.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the basic_string insert aliasing discussion in the referenced STL pull request and compare it with the approaches outlined here. Investigate which of the four cases can be handled without a temporary string, then establish performance measurements before deciding which optimization is worthwhile.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100