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

change to non optional utf8 function #640

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zunda-pixel
Copy link
Contributor

String.data(using)? -> Data(String.utf8)
String(data:encoding)? -> String(decoding:as)

@allevato
Copy link
Collaborator

Could you measure the performance of these changes? I have a suspicion that the Data initializer taking a Sequence<UInt8> might be slower than the String method from Foundation (though I'd be happy to be wrong).

You should be able to use the recently added --measure-instructions flag before and after your change to get rough numbers to start.

@zunda-pixel
Copy link
Contributor Author

I don't known how to use --measure-instructions.
is this swift test?

@zunda-pixel
Copy link
Contributor Author

zunda-pixel commented Sep 30, 2023

I found source code. but I don't known this code used in current Swift.

@allevato
Copy link
Collaborator

I don't known how to use --measure-instructions. is this swift test?

It's a swift-format flag. Try running the following commands with and without your change and report the number of instructions in each case:

swift-format lint --measure-instructions Package.swift
swift-format format --measure-instructions Package.swift

@zunda-pixel
Copy link
Contributor Author

zunda-pixel commented Oct 2, 2023

result is unstable?

Name Lint Format
Data(String.utf8) 83694608 103411109
String.data(using: .utf8) 89545458 130931785

String.data(using)? -> Data(String.utf8)
String(data:encoding)? -> String(decoding:as)
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.

None yet

2 participants