Explorar o código

complex: implement add/sub_assign directly

Josh Stone %!s(int64=7) %!d(string=hai) anos
pai
achega
d57c0c2879
Modificáronse 1 ficheiros con 4 adicións e 2 borrados
  1. 4 2
      complex/src/lib.rs

+ 4 - 2
complex/src/lib.rs

@@ -527,13 +527,15 @@ mod opassign {
 
     impl<T: Clone + NumAssign> AddAssign for Complex<T> {
         fn add_assign(&mut self, other: Complex<T>) {
-            *self = self.clone() + other;
+            self.re += other.re;
+            self.im += other.im;
         }
     }
 
     impl<T: Clone + NumAssign> SubAssign for Complex<T> {
         fn sub_assign(&mut self, other: Complex<T>) {
-            *self = self.clone() - other;
+            self.re -= other.re;
+            self.im -= other.im;
         }
     }