Skip to content

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.


// Are we done?
if i == len {
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