Skip to content

Commit

Permalink
Use non-overlapping swap for inner heapsort loop
Browse files Browse the repository at this point in the history
This regresses binary-size slightly for normal builds, but the important
release_lto_thin_opt_level_s config sees a small improvement in
binary-size and a larger types such as string and 1k see 2-3% run-time
improvements with this change.
  • Loading branch information
Voultapher committed Sep 4, 2024
1 parent a0e4303 commit 5439198
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions library/core/src/slice/sort/unstable/heapsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ where
break;
}

// Swap `node` with the greater child, move one step down, and continue sifting. This
// could be ptr::swap_nonoverlapping but that adds a significant amount of binary-size.
ptr::swap(v_base.add(node), v_base.add(child));
ptr::swap_nonoverlapping(v_base.add(node), v_base.add(child), 1);
}

node = child;
Expand Down

0 comments on commit 5439198

Please sign in to comment.