-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add Shift-JIS encoding support #29
Conversation
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.
Thank you for the PR. The changes seems good 👍
Once you have perform the comments, I am happy to merge. Would be too much to ask to add a small test to verify the usage? 😅
default: throw Error._unsupported(encoding: encoding) | ||
} | ||
} | ||
} | ||
|
||
extension Data { |
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.
Please, make the extension fileprivate
.
default: throw Error._unsupported(encoding: encoding) | ||
} | ||
} | ||
} | ||
|
||
extension Data { | ||
var encodedHexadecimals: [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.
private
or fileprivate
variables and functions are underscored in this library.
var encodedHexadecimals: [UInt8]? { | ||
let responseValues = self.withUnsafeBytes({ (pointer: UnsafeRawBufferPointer) -> [UInt8] in | ||
let unsafeBufferPointer = pointer.bindMemory(to: UInt8.self) | ||
let unsafePointer = unsafeBufferPointer.baseAddress! |
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.
Since this code will be repeated very often, I believe it is worth to change the force cast into a unsafelyUnwrapped
.
Sigh, I guess it would. I will make the changes myself. |
Alright, @rkyymmt and @rikiya-yamamoto. I have taken a deeper look at your code and saw that you had an unnecessary array allocation that was being executed for every scalar. I removed it and access the underlying byte representation directly. Performance should now be better, but still it is far from ideal since we are performing a round trip from Unicode Scalar -> String -> to Data. I am not very knowledgable on ShiftJIS, but I am sure there must be a way to transform Unicode Scalar to UInt8 directly. In any case, the code should now work and be faster than what you sent. Please test it out with your data. Regards |
Description
Add Shift-JIS encoding support.
(Shift-JIS used in Japan.)