Skip to content
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

Swift5.0: Change Data(bytes:) to Data(_:) #848

Merged
merged 3 commits into from
Mar 22, 2019

Conversation

tbkka
Copy link
Collaborator

@tbkka tbkka commented Mar 21, 2019

This is a pretty simple global substitution to stop using the deprecated Data(byte:) initializer.

The recommended alternative Data(_:) works with Swift 4 and later, so we don't need any compiler conditionals; we can just change the code.

Note: I've not tested the performance impacts; I believe the Data(byte:) initializer was faster at one time. Hopefully that's been addressed.

tbkka added 3 commits March 20, 2019 17:08
Technically, an assignment such as:
    var f: Float
    f = 1e-50
is an implicit conversion from a Double literal to a Float.
Swift 5 now warns when such conversions lose precision.

To suppress these, I've added explicit conversions to obtain:
    f = Float(1e-50)
Swift 5 has deprecated an old Data initializer.
Fortunately, the recommended form works back to Swift 4,
so we don't have to introduce any `#if swift` conditionals.
@tbkka
Copy link
Collaborator Author

tbkka commented Mar 21, 2019

With this, the only remaining Swift 5.0 issue is an API change for Data.withUnsafeBytes and Data.withUnsafeMutableBytes. That's being investigated in #843.

@tbkka tbkka changed the title Swift5.0: Change Data(byte:) to Data(_:) Swift5.0: Change Data(bytes:) to Data(_:) Mar 21, 2019
@tbkka tbkka requested review from allevato and thomasvl March 21, 2019 23:08
@tbkka
Copy link
Collaborator Author

tbkka commented Mar 21, 2019

Testing: I just verified (on Ubuntu 16.04) that this builds and passes the test suite using Swift 4.0, 4.0.2, 4.0.3, 4.1.2, 4.2.3, and the 5.0 snapshot from March 10.

@thomasvl
Copy link
Collaborator

Note: I've not tested the performance impacts; I believe the Data(byte:) initializer was faster at one time. Hopefully that's been addressed.

We likely also need to look at some of the JSON/TextFormat stuff because of the String changes.

@thomasvl thomasvl merged commit 6897be2 into apple:master Mar 22, 2019
@tbkka tbkka deleted the swift50-data-init branch March 29, 2019 23:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants