Ver Fonte

complex: implement add/sub_assign directly

Josh Stone há 7 anos atrás
pai
commit
d57c0c2879
1 ficheiros alterados com 4 adições e 2 exclusões
  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;
         }
     }