Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort: migrate from ouroboros to self_cell #4972

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 7 additions & 60 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sort/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
31 changes: 16 additions & 15 deletions src/uu/sort/src/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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();
Expand Down Expand Up @@ -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
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/uu/sort/src/ext_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sort/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down