Skip to content

Commit 7fb0f8a

Browse files
committed
sum: use div_ceil() from std
1 parent 28e9a88 commit 7fb0f8a

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

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

0 commit comments

Comments
 (0)