Simplify basic_sstring<> c_str()

Open
#113 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
performance

Research direction

Start by locating the basic_sstring<> c_str() implementation and its handle, then trace how whole-string and mid-string spans obtain their pointers. Simplify the handle access and preserve the special handling for spans that are already null terminated; done means the thread-safe sharing logic is removed for the stated cases without changing c_str() behavior.

Written by the indexing model from the issue text.

Description

The code in basic_sstring<> for handling c_str() is unnecessarily complex.

It seemed obvious when writing this that the c_str() value should be shared across the lifetime of the string and across threads, but given that the value is constant and that the vast majority of basic_sstring instances will be references to entire strings, having this extra thread safe logic to deal with sharing the c_str() value is not a good thing.

The logic should change, at a minimum, to:

  • Store the c_str() value in the handle without using thread-safe mechanisms
  • Retrieve the c_str() value from the handle without using thread-safe mechanisms
  • If the basic_sstring<> represents the end of the string (meaning the whole string, or that the end of the span is the end of the base span), we know it's already null terminated, so store the pointer to the head of the current span in the handle
  • Only otherwise, take action on dealing with a mid-string c_str()

It seems like a good idea to get rid of the shared state from the shared string, but this can be considered later.

Dominant language
C++
Stars
2
Forks
8
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

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.

More from Azure/m

All issues in Azure/m

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.