[swift-evolution] [Review] SE-0027 Expose code unit initializers on String

Charles Kissinger crk at akkyra.com
Mon Feb 15 11:43:33 CST 2016


> Proposal link:
> 
> https://github.com/apple/swift-evolution/blob/master/proposals/0027-string-from-code-units.md <https://github.com/apple/swift-evolution/blob/master/proposals/0027-string-from-code-units.md>
> What is your evaluation of the proposal?
I strongly support this proposal. It fills an important gap in the String API, and it would be of immediate benefit to me. 

Although the performance benefits of the proposed initializers are listed as a primary motivation for the proposal, I think it is important to add them for completeness of the String API as well. UTF code unit sequences are the standard, cross-platform serialization formats for Unicode text, and the native Swift String type should have full support for interconversion to and from UTF. 

> Is the problem being addressed significant enough to warrant a change to Swift?
Yes. This is a surprising omission from the API and a significant pain point for those of us doing certain kinds of parsing.

I would prefer that one additional String method be added that would allow code unit sequences to be directly *appended* to Strings:

String.appendContentsOf<S : SequenceType, Encoding: UnicodeCodecType where Encoding.CodeUnit == Input.Generator.Element>(_: S, encoding: Encoding.Type)

A brief discussion of this additional method, and the motivation for adding it, is in the later parts of the original discussion thread for this proposal.

My understanding is that a simple implementation of this method would not have immediate performance benefits as will be the case for the new initializers. Some reworking of the internals of String would be necessary for that. I think it should be added for the sake of API completeness though, with optimal performance perhaps coming somewhere down the road.

> Does this proposal fit well with the feel and direction of Swift?
Yes. It is a great improvement over forcing people to use intermediate null-terminated “C” strings to efficiently initialize a String from code units!

> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
N/A

> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
I participated in the mailing list discussion of this proposal, made suggestions for method name improvements, provided feedback on the text of the proposal, and looked through the existing and proposed String initialization code.

I’ve closely examined the performance characteristics of various methods of String/code-unit interconversion during the course of my work.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160215/e92d4950/attachment.html>


More information about the swift-evolution mailing list