Skip to content

Commit 2bf0a19

Browse files
replace mem::replace(..., Default::default()) with mem::take(...)
1 parent a8b02c8 commit 2bf0a19

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/interval_arithmetic.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn convert_log2_denom_ceil(numer: &mut BigInt, old_log2_denom: usize, new_log2_d
3131
if new_log2_denom >= old_log2_denom {
3232
*numer <<= new_log2_denom - old_log2_denom;
3333
} else {
34-
let mut numer_value = mem::replace(numer, Default::default());
34+
let mut numer_value = mem::take(numer);
3535
numer_value = -numer_value;
3636
numer_value >>= old_log2_denom - new_log2_denom;
3737
numer_value = -numer_value;
@@ -202,7 +202,7 @@ impl DyadicFractionInterval {
202202
pub fn set_negative_one(&mut self) {
203203
self.lower_bound_numer.set_one();
204204
self.lower_bound_numer <<= self.log2_denom;
205-
self.lower_bound_numer = -mem::replace(&mut self.lower_bound_numer, Default::default());
205+
self.lower_bound_numer = -mem::take(&mut self.lower_bound_numer);
206206
self.upper_bound_numer.clone_from(&self.lower_bound_numer);
207207
}
208208
pub fn into_ratio_range(self) -> (Ratio<BigInt>, Ratio<BigInt>) {
@@ -462,7 +462,7 @@ impl DyadicFractionInterval {
462462
self
463463
}
464464
pub fn square_assign(&mut self) {
465-
*self = mem::replace(self, Default::default()).into_square();
465+
*self = mem::take(self).into_square();
466466
}
467467
pub fn square(&self) -> Self {
468468
self.clone().into_square()
@@ -493,7 +493,7 @@ impl DyadicFractionInterval {
493493
}
494494
}
495495
pub fn sqrt_assign(&mut self) {
496-
*self = mem::replace(self, Default::default()).into_sqrt();
496+
*self = mem::take(self).into_sqrt();
497497
}
498498
pub fn into_sqrt(self) -> Self {
499499
Self::do_sqrt(Cow::Owned(self))
@@ -774,10 +774,10 @@ impl DyadicFractionInterval {
774774
pub fn abs_assign(&mut self) {
775775
let contains_zero = self.contains_zero();
776776
if self.lower_bound_numer.is_negative() {
777-
self.lower_bound_numer = -mem::replace(&mut self.lower_bound_numer, Default::default());
777+
self.lower_bound_numer = -mem::take(&mut self.lower_bound_numer);
778778
}
779779
if self.upper_bound_numer.is_negative() {
780-
self.upper_bound_numer = -mem::replace(&mut self.upper_bound_numer, Default::default());
780+
self.upper_bound_numer = -mem::take(&mut self.upper_bound_numer);
781781
}
782782
if self.lower_bound_numer > self.upper_bound_numer {
783783
mem::swap(&mut self.lower_bound_numer, &mut self.upper_bound_numer);
@@ -807,12 +807,12 @@ impl DyadicFractionInterval {
807807
self.clone().into_floor(new_log2_denom)
808808
}
809809
pub fn ceil_assign(&mut self, new_log2_denom: usize) {
810-
self.lower_bound_numer = -mem::replace(&mut self.lower_bound_numer, Default::default());
811-
self.upper_bound_numer = -mem::replace(&mut self.upper_bound_numer, Default::default());
810+
self.lower_bound_numer = -mem::take(&mut self.lower_bound_numer);
811+
self.upper_bound_numer = -mem::take(&mut self.upper_bound_numer);
812812
self.lower_bound_numer >>= self.log2_denom;
813813
self.upper_bound_numer >>= self.log2_denom;
814-
self.lower_bound_numer = -mem::replace(&mut self.lower_bound_numer, Default::default());
815-
self.upper_bound_numer = -mem::replace(&mut self.upper_bound_numer, Default::default());
814+
self.lower_bound_numer = -mem::take(&mut self.lower_bound_numer);
815+
self.upper_bound_numer = -mem::take(&mut self.upper_bound_numer);
816816
self.log2_denom = 0;
817817
self.convert_log2_denom(new_log2_denom);
818818
}

src/polynomial/factorization_over_integers.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,10 @@ impl FactorTreeInteriorNode<ModularInteger<BigInt, BigInt>> {
238238
}
239239
let old_left_product = set_modulus(self.left.product(), new_modulus);
240240
let old_right_product = set_modulus(self.right.product(), new_modulus);
241-
let old_left_bezout_coefficient = set_modulus(
242-
mem::replace(&mut self.left_bezout_coefficient, Default::default()),
243-
new_modulus,
244-
);
245-
let old_right_bezout_coefficient = set_modulus(
246-
mem::replace(&mut self.right_bezout_coefficient, Default::default()),
247-
new_modulus,
248-
);
241+
let old_left_bezout_coefficient =
242+
set_modulus(mem::take(&mut self.left_bezout_coefficient), new_modulus);
243+
let old_right_bezout_coefficient =
244+
set_modulus(mem::take(&mut self.right_bezout_coefficient), new_modulus);
249245
let error = &new_product - &old_left_product * &old_right_product;
250246
let (quotient, remainder) =
251247
(&old_left_bezout_coefficient * &error).div_rem(&old_right_product);

0 commit comments

Comments
 (0)