<https://github.com/apple/swift/pull/8325> (Merged 10 days ago)
> On 3 Apr 2017, at 20:32, Charlie Monroe wrote:
>
>> On Apr 3, 2017, at 9:25 PM, Ben Rimmington wrote:
>>
>>> On 3 Apr 2017, at 17:55, Tony Allevato wrote:
>>>
>>> I just checked with -O and without and was surprised to find that `let x =
>>> "abc" + "def" + "ghi"` wasn't collapsed into a single string literal
>>> "abcdefghi" in the generated assembly code. Maybe it's more difficult than
>>> it is in some other languages because of operator overloads and different
>>> kinds of text literals (strings, extended grapheme clusters, Unicode
>>> scalars)?
>>
>> Is this a regression since Swift 2.0 added the optimization?
>
> I'd say it's a regression since 3.0 since I remember testing the optimizer
> even being able to put together this during compile time:
>
> struct URLString {
> let urlString: String
>
> init(host: String, path: String, query: String) {
> self.urlString = "http://" + host + path + "?" + query
> }
> }
>
> URLString(host: "apple.com", path: "/mac", query: "target=imac")
>
> This produced a single string literal - I confirmed this using MachOView on
> the final binary...
>
>> * Concatenation of Swift string literals, including across multiple
>> lines, is
>> now a guaranteed compile-time optimization, even at `-Onone`.
>> **(19125926)**
>>
>> <https://github.com/apple/swift/blame/97db3931f2c5a21ea87ad6e71cdecbec325bff91/CHANGELOG.md#L1329-L1330>
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution