-
Notifications
You must be signed in to change notification settings - Fork 654
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
Simplify C string to String conversion in IOError.reasonForError #544
Conversation
Motivation: The stray space looks like an oversight. Modifications: Removed a stray space from the end of a string interpolation literal that's used to construct an error message. Result: The exact value (but not the meaning) of the error message string changes. Clients that match against the exact error message might break, but that's arguably bad practice.
Motivation: The standard library already has a String initializer that takes a null-terminated UTF-8 C string. There's no need to construct an UnsafeBufferPointer to use the Collection-based init(decoding:as:). Modifications: Replaced a manual pointer conversion with the appropriate stdlib API. Result: No change. Both version return the same String. The new version is is arguably more correct because it saves the memory-rebinding step. I haven't added new tests because the modified code is covered by SystemTest.testErrorsWorkCorrectly.
Can one of the admins verify this patch? |
1 similar comment
Can one of the admins verify this patch? |
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.
This looks reasonable to me! We're about to cut a release so I'm afraid this will slip into 1.10 (or 1.9.1, if we ship it), so I'll hold off merging for a little while.
@Lukasa Sure, no problem. 👍 |
@swift-nio-bot test this please |
* Simplify C string to String conversion in IOError.reasonForError Motivation: The standard library already has a String initializer that takes a null-terminated UTF-8 C string. There's no need to construct an UnsafeBufferPointer to use the Collection-based init(decoding:as:). Modifications: Replaced a manual pointer conversion with the appropriate stdlib API. Result: No change. Both version return the same String. The new version is is arguably more correct because it saves the memory-rebinding step. I haven't added new tests because the modified code is covered by SystemTest.testErrorsWorkCorrectly. Motivation: Explain here the context, and why you're making that change. What is the problem you're trying to solve. Modifications: Describe the modifications you've done. Result: After your change, what will change.
Motivation:
The standard library already has a String initializer that takes a
null-terminated UTF-8 C string. There's no need to construct an
UnsafeBufferPointer
to use theCollection
-basedinit(decoding:as:)
.Modifications:
Replaced a manual pointer conversion with the appropriate stdlib API.
I also removed a stray space from the end of the string interpolation literal
that's used to construct the error message. The stray space looked like an oversight.
Result:
The string API change doesn't change the result of the method. Both versions return the same
String
. The new version is is arguably more correct because it saves the memory-rebinding step. I haven't added new tests because the modified code is covered bySystemTest.testErrorsWorkCorrectly
.Removing the space at the end of the error message string changes the exact value (but not the meaning) of the error message string. Clients that match against the exact error message might break, but that's arguably bad practice.