Avoid utf8CString when when owned storage is not required#1829
Avoid utf8CString when when owned storage is not required#1829jmschonfeld merged 2 commits intoswiftlang:mainfrom
Conversation
|
@swift-ci please test |
|
Looks like more of the C function pointer nullability mismatch. |
Well, this is quite strange because |
|
@jmschonfeld no, I don't think that this conversion is allowed. This is an issue related to |
Given that macOS CI passed, this conversion must be allowed in some situations and the only difference in this function between macOS and Linux/Windows etc. is the symbol renaming I believe (which is disabled on macOS) |
Oh sorry I misunderstood. Yeah it looks like even building on macOS with the symbol renaming enabled it builds successfully, so sounds like it's a platform difference between the value of what |
|
@swift-ci please test |
1 similar comment
|
@swift-ci please test |
It isn't flag related, it is the platform ABI. Windows and Darwin disagree on what a |
93e9e87 to
9085110
Compare
|
@swift-ci please test |
1 similar comment
|
@swift-ci please test |
Avoids calling
utf8CStringwhen not necessaryMotivation:
I noticed we use
String.utf8CStringin a handful of places in Foundation. Since this property returns aContiguousArray<CChar>which is an owned type, it must copy the contents of the string into an array. Instead, we can usewithCStringwhich provides the same functionality, but can avoid a copy if the String already contains null terminated UTF-8 (which native strings do). Additionally, in some cases, we didn't actually need a null terminated string and we can usewithUTF8instead which also avoids copying when the String contains non-null terminated UTF-8 (which some bridged strings do as well). This should avoid copying these strings each time (when not required)Modifications:
Replace uses of
utf8CStringwithwithCString/withUTF8Result:
Copies are avoided when the string can provide access to an inner cstring or utf8 pointer
Testing:
Existing tests cover these modified functions