diff options
author | lloyd <[email protected]> | 2009-11-19 18:03:17 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-11-19 18:03:17 +0000 |
commit | 2ffa6f3f1616d7db3503600ac047a10b01a6bb54 (patch) | |
tree | 13b693b1ece3775407125e82d8acb7f69f524201 /src/math/bigint/bigint.cpp | |
parent | 46eb21cd08a0268d860eeef449e7474fb615b050 (diff) |
Add move assignment and constructor operators to BigInt. On macro benchmarks
(timing the test suite) there doesn't seem to be much of a difference either
way, but putting printfs in the implementations shows they are being used.
Since they pretty much can't possibly hurt (right?) and might well help a
lot in certain cases, it's worth including.
Todo: adding overloads to binary operators taking move operations might
be nice. Details in http://cpp-next.com/archive/2009/09/making-your-next-move/
Diffstat (limited to 'src/math/bigint/bigint.cpp')
-rw-r--r-- | src/math/bigint/bigint.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp index 7592ec439..36739f047 100644 --- a/src/math/bigint/bigint.cpp +++ b/src/math/bigint/bigint.cpp @@ -40,7 +40,7 @@ BigInt::BigInt(Sign s, u32bit size) } /* -* Construct a BigInt from a "raw" BigInt +* Copy constructor */ BigInt::BigInt(const BigInt& b) { @@ -100,6 +100,29 @@ BigInt::BigInt(RandomNumberGenerator& rng, u32bit bits) randomize(rng, bits); } +/** +* Move constructor +*/ +BigInt::BigInt(BigInt&& other) + { + reg.swap(other.reg); + signedness = other.signedness; + } + +/** +* Move assignment +*/ +BigInt& BigInt::operator=(BigInt&& other) + { + if(this != &other) + { + reg.swap(other.reg); + signedness = other.signedness; + } + + return (*this); + } + /* * Swap this BigInt with another */ |