Skip to content

Simplify basic_sstring<> c_str() #113

@EmJayGee

Description

@EmJayGee

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions