Skip to content

Commit ceac40e

Browse files
authored
Merge branch 'main' into 7903_pretty_print
2 parents 5318b98 + a5a9f7d commit ceac40e

File tree

6 files changed

+70
-58
lines changed

6 files changed

+70
-58
lines changed

Cargo.lock

Lines changed: 23 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ walkdir = "2.5"
349349
winapi-util = "0.1.8"
350350
windows-sys = { version = "0.59.0", default-features = false }
351351
xattr = "1.3.1"
352-
zip = { version = "2.2.2", default-features = false, features = ["deflate"] }
352+
zip = { version = "3.0.0", default-features = false, features = ["deflate"] }
353353

354354
hex = "0.4.3"
355355
md-5 = "0.10.6"

src/uu/ls/src/ls.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,26 +2576,21 @@ fn display_items(
25762576

25772577
for item in items {
25782578
#[cfg(unix)]
2579-
if config.inode || config.alloc_size {
2580-
let more_info = display_additional_leading_info(
2581-
item,
2582-
&padding_collection,
2583-
config,
2584-
&mut state.out,
2585-
)?;
2586-
2587-
write!(state.out, "{more_info}")?;
2588-
}
2579+
let should_display_leading_info = config.inode || config.alloc_size;
25892580
#[cfg(not(unix))]
2590-
if config.alloc_size {
2581+
let should_display_leading_info = config.alloc_size;
2582+
2583+
if should_display_leading_info {
25912584
let more_info = display_additional_leading_info(
25922585
item,
25932586
&padding_collection,
25942587
config,
25952588
&mut state.out,
25962589
)?;
2590+
25972591
write!(state.out, "{more_info}")?;
25982592
}
2593+
25992594
display_item_long(item, &padding_collection, config, state, dired, quoted)?;
26002595
}
26012596
} else {

src/uu/pr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ path = "src/pr.rs"
2020
[dependencies]
2121
clap = { workspace = true }
2222
uucore = { workspace = true, features = ["entries"] }
23-
quick-error = { workspace = true }
2423
itertools = { workspace = true }
2524
regex = { workspace = true }
2625
chrono = { workspace = true }
26+
thiserror = { workspace = true }
2727

2828
[[bin]]
2929
name = "pr"

src/uu/pr/src/pr.rs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
use chrono::{DateTime, Local};
1010
use clap::{Arg, ArgAction, ArgMatches, Command};
1111
use itertools::Itertools;
12-
use quick_error::ResultExt;
1312
use regex::Regex;
1413
use std::fs::{File, metadata};
1514
use std::io::{BufRead, BufReader, Lines, Read, Write, stdin, stdout};
1615
#[cfg(unix)]
1716
use std::os::unix::fs::FileTypeExt;
17+
use thiserror::Error;
1818

19-
use quick_error::quick_error;
2019
use uucore::display::Quotable;
2120
use uucore::error::UResult;
2221
use uucore::{format_usage, help_about, help_section, help_usage};
@@ -134,35 +133,21 @@ impl From<std::io::Error> for PrError {
134133
}
135134
}
136135

137-
quick_error! {
138-
#[derive(Debug)]
139-
enum PrError {
140-
Input(err: std::io::Error, path: String) {
141-
context(path: &'a str, err: std::io::Error) -> (err, path.to_owned())
142-
display("pr: Reading from input {path} gave error")
143-
source(err)
144-
}
145-
146-
UnknownFiletype(path: String) {
147-
display("pr: {path}: unknown filetype")
148-
}
149-
150-
EncounteredErrors(msg: String) {
151-
display("pr: {msg}")
152-
}
153-
154-
IsDirectory(path: String) {
155-
display("pr: {path}: Is a directory")
156-
}
157-
158-
IsSocket(path: String) {
159-
display("pr: cannot open {path}, Operation not supported on socket")
160-
}
161-
162-
NotExists(path: String) {
163-
display("pr: cannot open {path}, No such file or directory")
164-
}
165-
}
136+
#[derive(Debug, Error)]
137+
enum PrError {
138+
#[error("pr: Reading from input {1} gave error")]
139+
Input(std::io::Error, String),
140+
#[error("pr: {0}: unknown filetype")]
141+
UnknownFiletype(String),
142+
#[error("pr: {0}")]
143+
EncounteredErrors(String),
144+
#[error("pr: {0}: Is a directory")]
145+
IsDirectory(String),
146+
#[cfg(not(windows))]
147+
#[error("pr: cannot open {0}, Operation not supported on socket")]
148+
IsSocket(String),
149+
#[error("pr: cannot open {0}, No such file or directory")]
150+
NotExists(String),
166151
}
167152

168153
pub fn uu_app() -> Command {
@@ -795,9 +780,9 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
795780
#[cfg(unix)]
796781
ft if ft.is_socket() => Err(PrError::IsSocket(path_string)),
797782
ft if ft.is_dir() => Err(PrError::IsDirectory(path_string)),
798-
ft if ft.is_file() || ft.is_symlink() => {
799-
Ok(Box::new(File::open(path).context(path)?) as Box<dyn Read>)
800-
}
783+
ft if ft.is_file() || ft.is_symlink() => Ok(Box::new(
784+
File::open(path).map_err(|e| PrError::Input(e, path.to_string()))?,
785+
) as Box<dyn Read>),
801786
_ => Err(PrError::UnknownFiletype(path_string)),
802787
}
803788
})

src/uu/wc/src/count_fast.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use libc::S_IFIFO;
3232
#[cfg(any(target_os = "linux", target_os = "android"))]
3333
use uucore::pipes::{pipe, splice, splice_exact};
3434

35-
const BUF_SIZE: usize = 16 * 1024;
35+
const BUF_SIZE: usize = 256 * 1024;
3636
#[cfg(any(target_os = "linux", target_os = "android"))]
3737
const SPLICE_SIZE: usize = 128 * 1024;
3838

@@ -197,6 +197,23 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
197197
}
198198
}
199199

200+
/// A simple structure used to align a BUF_SIZE buffer to 32-byte boundary.
201+
///
202+
/// This is useful as bytecount uses 256-bit wide vector operations that run much
203+
/// faster on aligned data (at least on x86 with AVX2 support).
204+
#[repr(align(32))]
205+
struct AlignedBuffer {
206+
data: [u8; BUF_SIZE],
207+
}
208+
209+
impl Default for AlignedBuffer {
210+
fn default() -> Self {
211+
Self {
212+
data: [0; BUF_SIZE],
213+
}
214+
}
215+
}
216+
200217
/// Returns a WordCount that counts the number of bytes, lines, and/or the number of Unicode characters encoded in UTF-8 read via a Reader.
201218
///
202219
/// This corresponds to the `-c`, `-l` and `-m` command line flags to wc.
@@ -213,9 +230,9 @@ pub(crate) fn count_bytes_chars_and_lines_fast<
213230
handle: &mut R,
214231
) -> (WordCount, Option<io::Error>) {
215232
let mut total = WordCount::default();
216-
let mut buf = [0; BUF_SIZE];
233+
let buf: &mut [u8] = &mut AlignedBuffer::default().data;
217234
loop {
218-
match handle.read(&mut buf) {
235+
match handle.read(buf) {
219236
Ok(0) => return (total, None),
220237
Ok(n) => {
221238
if COUNT_BYTES {

0 commit comments

Comments
 (0)