Skip to content

Commit fb1874b

Browse files
authored
Merge pull request #6877 from cakebaker/use_div_ceil_from_std
Use `div_ceil()` from `std`
2 parents 3d4436a + cfe2c9f commit fb1874b

File tree

4 files changed

+6
-27
lines changed

4 files changed

+6
-27
lines changed

src/uu/cksum/src/cksum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use uucore::{
2222
format_usage, help_about, help_section, help_usage,
2323
line_ending::LineEnding,
2424
os_str_as_bytes, show,
25-
sum::{div_ceil, Digest},
25+
sum::Digest,
2626
};
2727

2828
const USAGE: &str = help_usage!("cksum.md");
@@ -124,7 +124,7 @@ where
124124
format!(
125125
"{} {}{}",
126126
sum.parse::<u16>().unwrap(),
127-
div_ceil(sz, options.output_bits),
127+
sz.div_ceil(options.output_bits),
128128
if not_file { "" } else { " " }
129129
),
130130
!not_file,
@@ -134,7 +134,7 @@ where
134134
format!(
135135
"{:0bsd_width$} {:bsd_width$}{}",
136136
sum.parse::<u16>().unwrap(),
137-
div_ceil(sz, options.output_bits),
137+
sz.div_ceil(options.output_bits),
138138
if not_file { "" } else { " " }
139139
),
140140
!not_file,

src/uu/du/src/du.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl StatPrinter {
562562
size,
563563
uucore::format::human::SizeFormat::Binary,
564564
),
565-
SizeFormat::BlockSize(block_size) => div_ceil(size, block_size).to_string(),
565+
SizeFormat::BlockSize(block_size) => size.div_ceil(block_size).to_string(),
566566
}
567567
}
568568

@@ -583,13 +583,6 @@ impl StatPrinter {
583583
}
584584
}
585585

586-
// This can be replaced with u64::div_ceil once it is stabilized.
587-
// This implementation approach is optimized for when `b` is a constant,
588-
// particularly a power of two.
589-
pub fn div_ceil(a: u64, b: u64) -> u64 {
590-
(a + b - 1) / b
591-
}
592-
593586
// Read file paths from the specified file, separated by null characters
594587
fn read_files_from(file_name: &str) -> Result<Vec<PathBuf>, std::io::Error> {
595588
let reader: Box<dyn BufRead> = if file_name == "-" {

src/uu/sum/src/sum.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ use uucore::{format_usage, help_about, help_usage, show};
1616
const USAGE: &str = help_usage!("sum.md");
1717
const ABOUT: &str = help_about!("sum.md");
1818

19-
// This can be replaced with usize::div_ceil once it is stabilized.
20-
// This implementation approach is optimized for when `b` is a constant,
21-
// particularly a power of two.
22-
const fn div_ceil(a: usize, b: usize) -> usize {
23-
(a + b - 1) / b
24-
}
25-
2619
fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
2720
let mut buf = [0; 4096];
2821
let mut bytes_read = 0;
@@ -41,7 +34,7 @@ fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
4134
}
4235

4336
// Report blocks read in terms of 1024-byte blocks.
44-
let blocks_read = div_ceil(bytes_read, 1024);
37+
let blocks_read = bytes_read.div_ceil(1024);
4538
(blocks_read, checksum)
4639
}
4740

@@ -66,7 +59,7 @@ fn sysv_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
6659
ret = (ret & 0xffff) + (ret >> 16);
6760

6861
// Report blocks read in terms of 512-byte blocks.
69-
let blocks_read = div_ceil(bytes_read, 512);
62+
let blocks_read = bytes_read.div_ceil(512);
7063
(blocks_read, ret as u16)
7164
}
7265

src/uucore/src/lib/features/sum.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,6 @@ impl Digest for CRC {
207207
}
208208
}
209209

210-
// This can be replaced with usize::div_ceil once it is stabilized.
211-
// This implementation approach is optimized for when `b` is a constant,
212-
// particularly a power of two.
213-
pub fn div_ceil(a: usize, b: usize) -> usize {
214-
(a + b - 1) / b
215-
}
216-
217210
pub struct BSD {
218211
state: u16,
219212
}

0 commit comments

Comments
 (0)