You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Allocate a buffer to use as scratch memory. We keep the length 0 so we can keep in it
906
-
// shallow copies of the contents of `v` without risking the dtors running on copies if
907
-
// `is_less` panics. When merging two sorted runs, this buffer holds a copy of the shorter run,
908
-
// which will always have length at most `len / 2`.
909
-
// `buf` is temporary = not passed around too much => using COOP_PREFERRED=true.
910
-
// @FIXME move definitions of `buf` and `runs` down, after while end > 0 {...}, just before they are used. Then benchmark if it makes (cache-related) difference.
911
-
let mut buf = Vec::<T, Global, true>::with_capacity(len / 2);
912
-
913
-
// In order to identify natural runs in `v`, we traverse it backwards. That might seem like a
914
-
// strange decision, but consider the fact that merges more often go in the opposite direction
915
-
// (forwards). According to benchmarks, merging forwards is slightly faster than merging
916
-
// backwards. To conclude, identifying runs by traversing backwards improves performance.
917
-
// `runs` is temporary = not passed around too much => using COOP_PREFERRED=true.
918
-
let mut runs: Vec<_, Global, true> = vec![];
919
-
let mut end = len;
920
-
while end > 0 {
921
-
// Find the next natural run, and reverse it if it's strictly descending.
922
-
let mut start = end - 1;
923
-
if start > 0 {
924
-
start -= 1;
925
-
unsafe {
926
-
if is_less(v.get_unchecked(start + 1), v.get_unchecked(start)) {
927
-
while start > 0 && is_less(v.get_unchecked(start), v.get_unchecked(start - 1)) {
928
-
start -= 1;
929
-
}
930
-
v[start..end].reverse();
931
-
} else {
932
-
while start > 0 && !is_less(v.get_unchecked(start), v.get_unchecked(start - 1))
0 commit comments