-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Eliminates redundant objects creations in NSData base64 decoding #2773
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
Conversation
Sources/Foundation/NSData.swift
Outdated
@@ -670,7 +671,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { | |||
- parameter options: Options for handling invalid input | |||
- returns: The decoded bytes. | |||
*/ | |||
private static func base64DecodeBytes(_ bytes: [UInt8], options: Base64DecodingOptions = []) -> [UInt8]? { | |||
private static func base64DecodeBytes(_ bytes: UnsafeRawBufferPointer, options: Base64DecodingOptions = []) -> [UInt8]? { |
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.
Rather than accepting an UnsafeRawBufferPointer
it would be safer to change the signature to :
private static func base64DecodeBytes<T: Collection>(_ bytes: T, options: Base64DecodingOptions = []) -> [UInt8]? where T.Element == UInt8 {
Then it could be called using:
NSData.base64DecodeBytes(base64String.utf8, ...)
and
NSData.base64DecodeBytes(base64Data, ...)
This has a 2nd benefit of avoiding the use of .utf8CString
which may have to reallocate if it needs more space since it appends a NUL
to the end of the buffer. This also eliminates the use of withUnsafeBytes
in the 2nd initialiser.
What do you think?
@swift-ci test linux |
4 similar comments
@swift-ci test linux |
@swift-ci test linux |
@swift-ci test linux |
@swift-ci test linux |
This is fine although could you just squash it down into a single commit please. I do have some decoding optimisations to add but I can rebase them on top of these ones. |
…to NSData base64 decoding.
0d55e8d
to
b070a51
Compare
Squashed |
@swift-ci please test |
1 similar comment
@swift-ci please test |
@swift-ci test and merge |
@swift-ci please test and merge |
No description provided.