Store squared limit to reduce operations.
This commit is contained in:
@@ -93,10 +93,11 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
opts.num + 1
|
opts.num + 1
|
||||||
};
|
};
|
||||||
|
let mut squared_limit = 0;
|
||||||
|
|
||||||
let prime_list = Arc::new(RwLock::new(prime_list_raw));
|
let prime_list = Arc::new(RwLock::new(prime_list_raw));
|
||||||
loop {
|
loop {
|
||||||
if (start < opts.num) && ((*prime_list.read().unwrap().last().unwrap_or(&0)).pow(2) >= (end as u64) ||
|
if (start < opts.num) && (squared_limit >= (end as u64) ||
|
||||||
(prime_list.read().unwrap().is_empty() && pending_tasks == 0))
|
(prime_list.read().unwrap().is_empty() && pending_tasks == 0))
|
||||||
{
|
{
|
||||||
let prime_list_clone = Arc::clone(&prime_list);
|
let prime_list_clone = Arc::clone(&prime_list);
|
||||||
@@ -156,6 +157,8 @@ fn main() {
|
|||||||
None => break,
|
None => break,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
squared_limit = prime_list.read().unwrap().last().unwrap().pow(2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no more tasks to be added, and all tasks have been processed
|
// no more tasks to be added, and all tasks have been processed
|
||||||
|
|||||||
Reference in New Issue
Block a user