This commit is contained in:
sylvestre
2023-06-26 03:08:19 +00:00
parent 10bd75632f
commit 92852d4a7a
15 changed files with 37 additions and 53 deletions
+17 -15
View File
@@ -319,6 +319,7 @@
<a href="#319" id="319">319</a>
<a href="#320" id="320">320</a>
<a href="#321" id="321">321</a>
<a href="#322" id="322">322</a>
</pre></div><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
// *
// * (c) Michael Debertol &lt;michael.debertol..AT..gmail.com&gt;
@@ -337,21 +338,22 @@
};
<span class="kw">use </span>memchr::memchr_iter;
<span class="kw">use </span>ouroboros::self_referencing;
<span class="kw">use </span>self_cell::self_cell;
<span class="kw">use </span>uucore::error::{UResult, USimpleError};
<span class="kw">use crate</span>::{numeric_str_cmp::NumInfo, GeneralF64ParseResult, GlobalSettings, Line, SortError};
<span class="doccomment">/// The chunk that is passed around between threads.
/// `lines` consist of slices into `buffer`.
</span><span class="attr">#[self_referencing(pub_extras)]
#[derive(Debug)]
</span><span class="kw">pub struct </span>Chunk {
<span class="kw">pub </span>buffer: Vec&lt;u8&gt;,
<span class="attr">#[borrows(buffer)]
#[covariant]
</span><span class="kw">pub </span>contents: ChunkContents&lt;<span class="lifetime">&#39;this</span>&gt;,
}
<span class="macro">self_cell!</span>(
<span class="doccomment">/// The chunk that is passed around between threads.
</span><span class="kw">pub struct </span>Chunk {
owner: Vec&lt;u8&gt;,
<span class="attr">#[covariant]
</span>dependent: ChunkContents,
}
<span class="kw">impl </span>{Debug}
);
<span class="attr">#[derive(Debug)]
</span><span class="kw">pub struct </span>ChunkContents&lt;<span class="lifetime">&#39;a</span>&gt; {
@@ -369,7 +371,7 @@
<span class="kw">impl </span>Chunk {
<span class="doccomment">/// Destroy this chunk and return its components to be reused.
</span><span class="kw">pub fn </span>recycle(<span class="kw-2">mut </span><span class="self">self</span>) -&gt; RecycledChunk {
<span class="kw">let </span>recycled_contents = <span class="self">self</span>.with_contents_mut(|contents| {
<span class="kw">let </span>recycled_contents = <span class="self">self</span>.with_dependent_mut(|<span class="kw">_</span>, contents| {
contents.lines.clear();
contents.line_data.selections.clear();
contents.line_data.num_infos.clear();
@@ -402,15 +404,15 @@
selections: recycled_contents.<span class="number">1</span>,
num_infos: recycled_contents.<span class="number">2</span>,
parsed_floats: recycled_contents.<span class="number">3</span>,
buffer: <span class="self">self</span>.into_heads().buffer,
buffer: <span class="self">self</span>.into_owner(),
}
}
<span class="kw">pub fn </span>lines(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>Vec&lt;Line&gt; {
<span class="kw-2">&amp;</span><span class="self">self</span>.borrow_contents().lines
<span class="kw-2">&amp;</span><span class="self">self</span>.borrow_dependent().lines
}
<span class="kw">pub fn </span>line_data(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>LineData {
<span class="kw-2">&amp;</span><span class="self">self</span>.borrow_contents().line_data
<span class="kw-2">&amp;</span><span class="self">self</span>.borrow_dependent().line_data
}
}
+1 -1
View File
@@ -444,7 +444,7 @@
<span class="doccomment">/// The function that is executed on the sorter thread.
</span><span class="kw">fn </span>sorter(receiver: <span class="kw-2">&amp;</span>Receiver&lt;Chunk&gt;, sender: <span class="kw-2">&amp;</span>SyncSender&lt;Chunk&gt;, settings: <span class="kw-2">&amp;</span>GlobalSettings) {
<span class="kw">while let </span><span class="prelude-val">Ok</span>(<span class="kw-2">mut </span>payload) = receiver.recv() {
payload.with_contents_mut(|contents| {
payload.with_dependent_mut(|<span class="kw">_</span>, contents| {
sort_by(<span class="kw-2">&amp;mut </span>contents.lines, settings, <span class="kw-2">&amp;</span>contents.line_data);
});
<span class="kw">if </span>sender.send(payload).is_err() {
+1 -1
View File
@@ -843,7 +843,7 @@
file_number: file.file_number,
});
file.current_chunk.with_contents(|contents| {
file.current_chunk.with_dependent(|<span class="kw">_</span>, contents| {
<span class="kw">let </span>current_line = <span class="kw-2">&amp;</span>contents.lines[file.line_idx];
<span class="kw">if </span>settings.unique {
<span class="kw">if let </span><span class="prelude-val">Some</span>(prev) = <span class="kw-2">&amp;</span>prev {
+1 -19
View File
@@ -765,15 +765,6 @@
<a href="#765" id="765">765</a>
<a href="#766" id="766">766</a>
<a href="#767" id="767">767</a>
<a href="#768" id="768">768</a>
<a href="#769" id="769">769</a>
<a href="#770" id="770">770</a>
<a href="#771" id="771">771</a>
<a href="#772" id="772">772</a>
<a href="#773" id="773">773</a>
<a href="#774" id="774">774</a>
<a href="#775" id="775">775</a>
<a href="#776" id="776">776</a>
</pre></div><pre class="rust"><code><span class="comment">// TODO fix broken links
</span><span class="attr">#![allow(rustdoc::broken_intra_doc_links)]
</span><span class="doccomment">//! All utils return exit with an exit code. Usually, the following scheme is used:
@@ -1172,7 +1163,7 @@
<span class="kw">fn </span>fmt(<span class="kw-2">&amp;</span><span class="self">self</span>, f: <span class="kw-2">&amp;mut </span>Formatter&lt;<span class="lifetime">&#39;_</span>&gt;) -&gt; <span class="prelude-ty">Result</span>&lt;(), std::fmt::Error&gt; {
<span class="kw">use </span>std::io::ErrorKind::<span class="kw-2">*</span>;
<span class="kw">let </span><span class="kw-2">mut </span>message;
<span class="kw">let </span>message;
<span class="kw">let </span>message = <span class="kw">if </span><span class="self">self</span>.inner.raw_os_error().is_some() {
<span class="comment">// These are errors that come directly from the OS.
// We want to normalize their messages across systems,
@@ -1200,7 +1191,6 @@
// (https://github.com/rust-lang/rust/issues/86442)
// are stabilized, we should add them to the match statement.
</span>message = strip_errno(<span class="kw-2">&amp;</span><span class="self">self</span>.inner);
capitalize(<span class="kw-2">&amp;mut </span>message);
<span class="kw-2">&amp;</span>message
}
}
@@ -1211,7 +1201,6 @@
// a file that was not found.
// There are also errors with entirely custom messages.
</span>message = <span class="self">self</span>.inner.to_string();
capitalize(<span class="kw-2">&amp;mut </span>message);
<span class="kw-2">&amp;</span>message
};
<span class="kw">if let </span><span class="prelude-val">Some</span>(ctx) = <span class="kw-2">&amp;</span><span class="self">self</span>.context {
@@ -1222,13 +1211,6 @@
}
}
<span class="doccomment">/// Capitalize the first character of an ASCII string.
</span><span class="kw">fn </span>capitalize(text: <span class="kw-2">&amp;mut </span>str) {
<span class="kw">if let </span><span class="prelude-val">Some</span>(first) = text.get_mut(..<span class="number">1</span>) {
first.make_ascii_uppercase();
}
}
<span class="doccomment">/// Strip the trailing &quot; (os error XX)&quot; from io error strings.
</span><span class="kw">pub fn </span>strip_errno(err: <span class="kw-2">&amp;</span>std::io::Error) -&gt; String {
<span class="kw">let </span><span class="kw-2">mut </span>msg = err.to_string();
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long