-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pitch] Span
-providing properties in the standard library
#2620
base: main
Are you sure you want to change the base?
Conversation
var bytes: RawSpan { get } | ||
} | ||
|
||
extension String.UTF8View { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: What is the behavior (and what are the performance characteristics) of this operation when a String
has storage other than contiguous UTF-8? Would it be desirable to return an optional, or alternatively require the user to know or have called makeContiguousUTF8()
on the String
as a precondition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behind the scenes, we are implementing a new "lazy eager bridging" behaviour for bridged Array
and bridged String
. They will always succeed, but they will sometimes entail an allocation and copy (i.e. "usually O(1), sometimes O(n)".) An initial step is here. For native non-bridged instances, always O(1).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! The implementation details would of course be out of scope for this text, but might be worth calling out here the performance implications for calling storage
and bytes
on these types, pros and cons for usability vs predictability, etc. (given that this is supposed to be a safe, performant API).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appended a paragraph to the detailed design to spell this out.
84708d7
to
670ac2d
Compare
Continuing the work of adding
Span
, this is a proposal to add the ability to useSpan
as computed properties on standard library types, includingArray
.