]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #104672 - Voultapher:unify-sort-modules, r=thomcc
authorMichael Goulet <michael@errs.io>
Sat, 21 Jan 2023 02:33:21 +0000 (21:33 -0500)
committerGitHub <noreply@github.com>
Sat, 21 Jan 2023 02:33:21 +0000 (21:33 -0500)
Unify stable and unstable sort implementations in same core module

This moves the stable sort implementation to the core::slice::sort module. By virtue of being in core it can't access `Vec`. The two `Vec` used by merge sort, `buf` and `runs`, are modelled as custom types that implement the very limited required `Vec` interface with the help of provided allocation and free functions. This is done to allow future re-use of functions and logic between stable and unstable sort. Such as `insert_head`.

This is in preparation of #100856 and #104116. It only moves code, it *doesn't* change any of the sort related logic. This unlocks the ability to share `insert_head`, `insert_tail`, `swap_if_less` `merge` and more.

Tagging ````@Mark-Simulacrum```` I hope this allows progress on #100856, by moving `merge_sort` here I hope future changes will be easier to review.

1  2 
library/alloc/src/slice.rs
library/core/src/slice/mod.rs
library/core/src/slice/sort.rs

Simple merge
Simple merge
index 3ac01d1727513ec99ae350740263314bd0442dd9,3da00b8f79672b23e9a69ac0abdbc3f6a4c45a1c..2181f9a811855f7ac2a39352b481f0f865e193d5
@@@ -3,8 -3,11 +3,11 @@@
  //! This module contains a sorting algorithm based on Orson Peters' pattern-defeating quicksort,
  //! published at: <https://github.com/orlp/pdqsort>
  //!
 -//! Unstable sorting is compatible with libcore because it doesn't allocate memory, unlike our
 +//! Unstable sorting is compatible with core because it doesn't allocate memory, unlike our
  //! stable sorting implementation.
+ //!
+ //! In addition it also contains the core logic of the stable sort used by `slice::sort` based on
+ //! TimSort.
  
  use crate::cmp;
  use crate::mem::{self, MaybeUninit, SizedTypeProperties};