Skip to content

Commit

Permalink
[CORE] Use saturated add in download
Browse files Browse the repository at this point in the history
  • Loading branch information
Bwc9876 committed Aug 4, 2023
1 parent 82ac21a commit 5e04b52
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions owmods_core/src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,12 @@ impl ProgressBar {
pub fn inc(&mut self, amount: ProgressValue) {
const THROTTLING_AMOUNT: ProgressValue = 30;

self.progress = if self.progress + amount >= self.len {
let new_progress = self.progress.saturating_add(amount);

self.progress = if new_progress >= self.len {
self.len
} else {
self.progress + amount
new_progress
};

if self.progress - self.throttled_progress > self.len / THROTTLING_AMOUNT {
Expand Down

0 comments on commit 5e04b52

Please sign in to comment.