sort: migrate from ouroboros to self_cell

This commit is contained in:
Daniel Hofstetter 2023-06-12 15:58:49 +02:00
parent 66723e0961
commit 6ebfaf4b9d
6 changed files with 27 additions and 79 deletions

67
Cargo.lock generated
View file

@ -2,12 +2,6 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "Inflector"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
[[package]]
name = "adler"
version = "1.0.2"
@ -43,12 +37,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "aliasable"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd"
[[package]]
name = "android-tzdata"
version = "0.1.1"
@ -1620,29 +1608,6 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "ouroboros"
version = "0.15.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1358bd1558bd2a083fed428ffeda486fbfb323e698cdda7794259d592ca72db"
dependencies = [
"aliasable",
"ouroboros_macro",
]
[[package]]
name = "ouroboros_macro"
version = "0.15.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f7d21ccd03305a674437ee1248f3ab5d4b1db095cf1caf49f1713ddf61956b7"
dependencies = [
"Inflector",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "output_vt100"
version = "0.1.3"
@ -1781,30 +1746,6 @@ dependencies = [
"yansi",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.20+deprecated"
@ -2082,6 +2023,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
[[package]]
name = "self_cell"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a3926e239738d36060909ffe6f511502f92149a45a1fade7fe031cb2d33e88b"
[[package]]
name = "selinux"
version = "0.4.0"
@ -3145,9 +3092,9 @@ dependencies = [
"fnv",
"itertools",
"memchr",
"ouroboros",
"rand",
"rayon",
"self_cell",
"tempfile",
"unicode-width",
"uucore",

View file

@ -300,7 +300,6 @@ num-traits = "0.2.15"
number_prefix = "0.4"
once_cell = "1.18.0"
onig = { version = "~6.4", default-features = false }
ouroboros = "0.15.6"
parse_datetime = "0.4.0"
phf = "0.11.1"
phf_codegen = "0.11.1"
@ -314,6 +313,7 @@ regex = "1.8.4"
rstest = "0.17.0"
rust-ini = "0.19.0"
same-file = "1.0.6"
self_cell = "1.0.0"
selinux = "0.4"
signal-hook = "0.3.15"
smallvec = { version = "1.10", features = ["union"] }

View file

@ -22,9 +22,9 @@ ctrlc = { workspace = true }
fnv = { workspace = true }
itertools = { workspace = true }
memchr = { workspace = true }
ouroboros = { workspace = true }
rand = { workspace = true }
rayon = { workspace = true }
self_cell = { workspace = true }
tempfile = { workspace = true }
unicode-width = { workspace = true }
uucore = { workspace = true, features = ["fs"] }

View file

@ -16,21 +16,22 @@ use std::{
};
use memchr::memchr_iter;
use ouroboros::self_referencing;
use self_cell::self_cell;
use uucore::error::{UResult, USimpleError};
use crate::{numeric_str_cmp::NumInfo, GeneralF64ParseResult, GlobalSettings, Line, SortError};
/// The chunk that is passed around between threads.
/// `lines` consist of slices into `buffer`.
#[self_referencing(pub_extras)]
#[derive(Debug)]
pub struct Chunk {
pub buffer: Vec<u8>,
#[borrows(buffer)]
#[covariant]
pub contents: ChunkContents<'this>,
}
self_cell!(
/// The chunk that is passed around between threads.
pub struct Chunk {
owner: Vec<u8>,
#[covariant]
dependent: ChunkContents,
}
impl {Debug}
);
#[derive(Debug)]
pub struct ChunkContents<'a> {
@ -48,7 +49,7 @@ pub struct LineData<'a> {
impl Chunk {
/// Destroy this chunk and return its components to be reused.
pub fn recycle(mut self) -> RecycledChunk {
let recycled_contents = self.with_contents_mut(|contents| {
let recycled_contents = self.with_dependent_mut(|_, contents| {
contents.lines.clear();
contents.line_data.selections.clear();
contents.line_data.num_infos.clear();
@ -81,15 +82,15 @@ impl Chunk {
selections: recycled_contents.1,
num_infos: recycled_contents.2,
parsed_floats: recycled_contents.3,
buffer: self.into_heads().buffer,
buffer: self.into_owner(),
}
}
pub fn lines(&self) -> &Vec<Line> {
&self.borrow_contents().lines
&self.borrow_dependent().lines
}
pub fn line_data(&self) -> &LineData {
&self.borrow_contents().line_data
&self.borrow_dependent().line_data
}
}

View file

@ -158,7 +158,7 @@ fn reader_writer<
/// The function that is executed on the sorter thread.
fn sorter(receiver: &Receiver<Chunk>, sender: &SyncSender<Chunk>, settings: &GlobalSettings) {
while let Ok(mut payload) = receiver.recv() {
payload.with_contents_mut(|contents| {
payload.with_dependent_mut(|_, contents| {
sort_by(&mut contents.lines, settings, &contents.line_data);
});
if sender.send(payload).is_err() {

View file

@ -288,7 +288,7 @@ impl<'a> FileMerger<'a> {
file_number: file.file_number,
});
file.current_chunk.with_contents(|contents| {
file.current_chunk.with_dependent(|_, contents| {
let current_line = &contents.lines[file.line_idx];
if settings.unique {
if let Some(prev) = &prev {