Skip to content

Improve performance of Product2.distance(from:to:) #40

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

Merged
merged 1 commit into from
Nov 6, 2020

Conversation

timvermeulen
Copy link
Contributor

@timvermeulen timvermeulen commented Nov 2, 2020

This PR gets rid of any unnecessary computations in Product2.distance(from:to:). In particular, it now only does a single pass over base2 in the worst case (instead of 3), and for non-random-access collections it no longer does more index calculations than the default implementation of distance(from:to:).

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

@timvermeulen timvermeulen changed the title Improve performance of Product.distance(from:to:) Improve performance of Product2.distance(from:to:) Nov 2, 2020
@natecook1000
Copy link
Member

Looks great! And thanks for including the illustrative comments 🖼️

@natecook1000 natecook1000 merged commit 6933a31 into apple:main Nov 6, 2020
@timvermeulen timvermeulen deleted the product-distance branch November 6, 2020 21:15
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