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

In partial_insertion_sort, moved the SHORTEST_SHIFTING check outside of loop #1226

Closed
wants to merge 1 commit into from

Conversation

zommiommy
Copy link

@zommiommy zommiommy commented Jan 14, 2025

The check does not depend on the loop and can be performed at the start.
While the compiler probably optimizes this, it was confusing to read.

…f loop

While the compiler probably optimizes this, it was confusing to read.
Copy link
Member

@cuviper cuviper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this code was originally an adaptation of the standard library's sort, although that's since been replaced by rust-lang/rust#124032.

@@ -238,11 +243,6 @@ where
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the SHORTEST_SHIFTING condition is moved up, it changes this case that would have returned true. I haven't fully analyzed that effect, but it's not just about "readability" at that point.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right. The behaviour on short sorted slices changes, my bad.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then I'll close this - thanks anyway!

@cuviper cuviper closed this Jan 14, 2025
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