Add new Fw::StringBase type for strings backed by immutable string literals #4269
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change Description
Provides a new
Fw::StaticString
type which is a string backed by aconst char*
string literal. This mirrors the design ofFw::ExternalString
but this type can be initialized with aconst char*
instead ofFw::ExternalString
which requires a mutablechar*
pointer.Rationale
This was devised during work to optimize string-handling critical sections and reduce data copying. We needed a string type that could wrap a string literal without requiring internal storage or copying.
Fw::ExternalString
nearly fit the bill but could not be initialized with constant string literals. This new type fills that gap.Testing/Review Recommendations
Use in place of any
Fw::StringBase
type. Example usage:Future Work
Only marginally-related here but wanted to note that, for a string type like this which should have a constant length, I was not able to figure out a way to override the
length
function for use in serializing. Instead, the serialization code is forced to useStringBase::length
which usesFw::StringUtils::string_length
and it becomes an O(n) operation when it could be O(1).AI Usage (see policy)
N/A