Skip to content

Commit

Permalink
simplify ceiling division
Browse files Browse the repository at this point in the history
  • Loading branch information
ttlajus committed Aug 3, 2022
1 parent dacadad commit cbb706d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 10 deletions.
4 changes: 1 addition & 3 deletions src/torrent/v1/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,7 @@ impl TorrentBuilder {
let path = path.as_ref();
let length = path.metadata()?.len();
let piece_length = util::i64_to_u64(piece_length)?;
let pieces_total = util::u64_to_usize(
(util::u64_to_f64(length)? / util::u64_to_f64(piece_length)?).ceil() as u64,
)?;
let pieces_total = util::u64_to_usize((length + (piece_length - 1)) / piece_length)?;
let mut pieces = vec![vec![]; pieces_total];

pieces
Expand Down
7 changes: 0 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use conv::ValueFrom;
use std::borrow::Cow;
use std::convert::TryFrom;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -40,12 +39,6 @@ pub(crate) fn u64_to_i64(src: u64) -> Result<i64, LavaTorrentError> {
})
}

pub(crate) fn u64_to_f64(src: u64) -> Result<f64, LavaTorrentError> {
f64::value_from(src).map_err(|_| {
LavaTorrentError::FailedNumericConv(Cow::Owned(format!("[{}] does not fit into f64.", src)))
})
}

// this method is recursive, i.e. entries in subdirectories
// are also returned
//
Expand Down

0 comments on commit cbb706d

Please sign in to comment.