Skip to content

Commit def011f

Browse files
authored
Merge branch 'main' into sort_performan-ce
2 parents 2c4cf3e + eb4ce08 commit def011f

File tree

16 files changed

+725
-13
lines changed

16 files changed

+725
-13
lines changed

Cargo.lock

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

deny.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ skip = [
107107
{ name = "rand_core", version = "0.6.4" },
108108
# utmp-classic
109109
{ name = "zerocopy", version = "0.7.35" },
110+
# zerocopy
111+
{ name = "zerocopy-derive", version = "0.7.35" },
110112
# divans/codspeed tooling
111113
{ name = "nix", version = "0.29.0" },
112114
]

src/uu/cp/src/copydir.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
#[cfg(windows)]
1010
use std::borrow::Cow;
1111
use std::collections::{HashMap, HashSet};
12+
use std::convert::identity;
1213
use std::env;
13-
use std::fs;
14+
use std::fs::{self, exists};
1415
use std::io;
1516
use std::path::{Path, PathBuf, StripPrefixError};
1617

@@ -20,10 +21,9 @@ use uucore::error::UIoError;
2021
use uucore::fs::{
2122
FileInformation, MissingHandling, ResolveMode, canonicalize, path_ends_with_terminator,
2223
};
23-
use uucore::translate;
24-
2524
use uucore::show;
2625
use uucore::show_error;
26+
use uucore::translate;
2727
use uucore::uio_error;
2828
use walkdir::{DirEntry, WalkDir};
2929

@@ -194,15 +194,23 @@ impl Entry {
194194
get_local_to_root_parent(&source_absolute, context.root_parent.as_deref())?;
195195
if no_target_dir {
196196
let source_is_dir = source.is_dir();
197-
if path_ends_with_terminator(context.target) && source_is_dir {
197+
if path_ends_with_terminator(context.target)
198+
&& source_is_dir
199+
&& !exists(context.target).is_ok_and(identity)
200+
{
198201
if let Err(e) = fs::create_dir_all(context.target) {
199202
eprintln!(
200203
"{}",
201204
translate!("cp-error-failed-to-create-directory", "error" => e)
202205
);
203206
}
204-
} else {
205-
descendant = descendant.strip_prefix(context.root)?.to_path_buf();
207+
} else if let Some(stripped) = context
208+
.root
209+
.components()
210+
.next_back()
211+
.and_then(|stripped| descendant.strip_prefix(stripped).ok())
212+
{
213+
descendant = stripped.to_path_buf();
206214
}
207215
} else if context.root == Path::new(".") && context.target.is_dir() {
208216
// Special case: when copying current directory (.) to an existing directory,

src/uu/cut/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ memchr = { workspace = true }
2424
bstr = { workspace = true }
2525
fluent = { workspace = true }
2626

27+
[dev-dependencies]
28+
divan = { workspace = true }
29+
tempfile = { workspace = true }
30+
uucore = { workspace = true, features = ["benchmark"] }
31+
2732
[[bin]]
2833
name = "cut"
2934
path = "src/main.rs"
35+
36+
[[bench]]
37+
name = "cut_bench"
38+
harness = false

src/uu/cut/benches/cut_bench.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
use divan::{Bencher, black_box};
7+
use uu_cut::uumain;
8+
use uucore::benchmark::{run_util_function, setup_test_file, text_data};
9+
10+
/// Benchmark cutting specific byte ranges
11+
#[divan::bench]
12+
fn cut_bytes(bencher: Bencher) {
13+
let data = text_data::generate_by_lines(100_000, 80);
14+
let file_path = setup_test_file(&data);
15+
16+
bencher.bench(|| {
17+
black_box(run_util_function(
18+
uumain,
19+
&["-b", "1-20", file_path.to_str().unwrap()],
20+
));
21+
});
22+
}
23+
24+
/// Benchmark cutting specific character ranges
25+
#[divan::bench]
26+
fn cut_characters(bencher: Bencher) {
27+
let data = text_data::generate_mixed_data(100_000);
28+
let file_path = setup_test_file(&data);
29+
30+
bencher.bench(|| {
31+
black_box(run_util_function(
32+
uumain,
33+
&["-c", "5-30", file_path.to_str().unwrap()],
34+
));
35+
});
36+
}
37+
38+
/// Benchmark cutting fields with tab delimiter
39+
#[divan::bench]
40+
fn cut_fields_tab(bencher: Bencher) {
41+
let mut data = Vec::new();
42+
for i in 0..100_000 {
43+
let line = format!("field1\tfield2_{i}\tfield3\tfield4\tfield5\n");
44+
data.extend_from_slice(line.as_bytes());
45+
}
46+
let file_path = setup_test_file(&data);
47+
48+
bencher.bench(|| {
49+
black_box(run_util_function(
50+
uumain,
51+
&["-f", "2,4", file_path.to_str().unwrap()],
52+
));
53+
});
54+
}
55+
56+
/// Benchmark cutting fields with custom delimiter
57+
#[divan::bench]
58+
fn cut_fields_custom_delim(bencher: Bencher) {
59+
let mut data = Vec::new();
60+
for i in 0..100_000 {
61+
let line = format!("apple,banana_{i},cherry,date,elderberry\n");
62+
data.extend_from_slice(line.as_bytes());
63+
}
64+
let file_path = setup_test_file(&data);
65+
66+
bencher.bench(|| {
67+
black_box(run_util_function(
68+
uumain,
69+
&["-d", ",", "-f", "1,3,5", file_path.to_str().unwrap()],
70+
));
71+
});
72+
}
73+
74+
fn main() {
75+
divan::main();
76+
}

src/uu/hashsum/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ fluent = { workspace = true }
2525
[[bin]]
2626
name = "hashsum"
2727
path = "src/main.rs"
28+
29+
[dev-dependencies]
30+
divan = { workspace = true }
31+
tempfile = { workspace = true }
32+
uucore = { workspace = true, features = ["benchmark"] }
33+
34+
[[bench]]
35+
name = "hashsum_bench"
36+
harness = false

0 commit comments

Comments
 (0)