@@ -80,7 +80,6 @@ A big unsigned integer type.
80
80
A BigUint-typed value BigUint { data: @[a, b, c] } represents a number
81
81
(a + b * BigDigit::base + c * BigDigit::base^2).
82
82
*/
83
- #[ deriving( Clone ) ]
84
83
pub struct BigUint {
85
84
priv data : ~[ BigDigit ]
86
85
}
@@ -681,7 +680,7 @@ priv fn get_radix_base(radix: uint) -> (uint, uint) {
681
680
}
682
681
683
682
/// A Sign is a BigInt's composing element.
684
- #[ deriving( Eq , Clone ) ]
683
+ #[ deriving( Eq ) ]
685
684
pub enum Sign { Minus , Zero , Plus }
686
685
687
686
impl Ord for Sign {
@@ -727,7 +726,6 @@ impl Neg<Sign> for Sign {
727
726
}
728
727
729
728
/// A big signed integer type.
730
- #[ deriving( Clone ) ]
731
729
pub struct BigInt {
732
730
priv sign : Sign ,
733
731
priv data : BigUint
@@ -827,8 +825,8 @@ impl Signed for BigInt {
827
825
#[ inline( always) ]
828
826
fn abs ( & self ) -> BigInt {
829
827
match self . sign {
830
- Plus | Zero => self . clone ( ) ,
831
- Minus => BigInt :: from_biguint ( Plus , self . data . clone ( ) )
828
+ Plus | Zero => copy * self ,
829
+ Minus => BigInt :: from_biguint ( Plus , copy self . data )
832
830
}
833
831
}
834
832
@@ -852,8 +850,8 @@ impl Add<BigInt, BigInt> for BigInt {
852
850
#[ inline( always) ]
853
851
fn add ( & self , other : & BigInt ) -> BigInt {
854
852
match ( self . sign , other. sign ) {
855
- ( Zero , _) => other. clone ( ) ,
856
- ( _, Zero ) => self . clone ( ) ,
853
+ ( Zero , _) => copy * other,
854
+ ( _, Zero ) => copy * self ,
857
855
( Plus , Plus ) => BigInt :: from_biguint ( Plus ,
858
856
self . data + other. data ) ,
859
857
( Plus , Minus ) => self - ( -* other) ,
@@ -868,7 +866,7 @@ impl Sub<BigInt, BigInt> for BigInt {
868
866
fn sub ( & self , other : & BigInt ) -> BigInt {
869
867
match ( self . sign , other. sign ) {
870
868
( Zero , _) => -other,
871
- ( _, Zero ) => self . clone ( ) ,
869
+ ( _, Zero ) => copy * self ,
872
870
( Plus , Plus ) => match self . data . cmp ( & other. data ) {
873
871
Less => BigInt :: from_biguint ( Minus , other. data - self . data ) ,
874
872
Greater => BigInt :: from_biguint ( Plus , self . data - other. data ) ,
@@ -915,7 +913,7 @@ impl Rem<BigInt, BigInt> for BigInt {
915
913
impl Neg < BigInt > for BigInt {
916
914
#[ inline( always) ]
917
915
fn neg ( & self ) -> BigInt {
918
- BigInt :: from_biguint ( self . sign . neg ( ) , self . data . clone ( ) )
916
+ BigInt :: from_biguint ( self . sign . neg ( ) , copy self . data )
919
917
}
920
918
}
921
919
@@ -1102,9 +1100,9 @@ pub impl BigInt {
1102
1100
1103
1101
#[cfg(test)]
1104
1102
mod biguint_tests {
1105
- use super::*;
1106
1103
use core::num::{IntConvertible, Zero, One, FromStrRadix};
1107
1104
use core::cmp::{Less, Equal, Greater};
1105
+ use super::{BigUint, BigDigit};
1108
1106
1109
1107
#[test]
1110
1108
fn test_from_slice() {
@@ -1392,10 +1390,10 @@ mod biguint_tests {
1392
1390
let c = BigUint :: from_slice ( cVec) ;
1393
1391
1394
1392
if !a. is_zero ( ) {
1395
- assert ! ( c. div_rem( & a) == ( b . clone ( ) , Zero :: zero( ) ) ) ;
1393
+ assert ! ( c. div_rem( & a) == ( copy b , Zero :: zero( ) ) ) ;
1396
1394
}
1397
1395
if !b. is_zero ( ) {
1398
- assert ! ( c. div_rem( & b) == ( a . clone ( ) , Zero :: zero( ) ) ) ;
1396
+ assert ! ( c. div_rem( & b) == ( copy a , Zero :: zero( ) ) ) ;
1399
1397
}
1400
1398
}
1401
1399
@@ -1557,7 +1555,7 @@ mod biguint_tests {
1557
1555
1558
1556
#[cfg(test)]
1559
1557
mod bigint_tests {
1560
- use super::* ;
1558
+ use super::{BigInt, BigUint, BigDigit, Sign, Minus, Zero, Plus} ;
1561
1559
use core::cmp::{Less, Equal, Greater};
1562
1560
use core::num::{IntConvertible, Zero, One, FromStrRadix};
1563
1561
0 commit comments