diff options
| author | bors <bors@rust-lang.org> | 2014-02-19 21:56:51 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-19 21:56:51 -0800 |
| commit | 0cc8ba0c2030720750c6166ad898ca192c695ffc (patch) | |
| tree | d421ed57c72eb552ba07f0b423fda54ada33efa8 /src/libnum/bigint.rs | |
| parent | 801f8f67f81c06891964dec0d0930029fb203b89 (diff) | |
| parent | 33923f47e3f90442ae3c604d8ea80992b71611f7 (diff) | |
| download | rust-0cc8ba0c2030720750c6166ad898ca192c695ffc.tar.gz rust-0cc8ba0c2030720750c6166ad898ca192c695ffc.zip | |
auto merge of #12244 : pcwalton/rust/deuniquevectorpatterns, r=pcwalton
Preparatory work for removing unique vectors from the language, which is itself preparatory work for dynamically sized types. r? @brson
Diffstat (limited to 'src/libnum/bigint.rs')
| -rw-r--r-- | src/libnum/bigint.rs | 43 |
1 files changed, 18 insertions, 25 deletions
diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index 345dce12fed..7197b0dba1d 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -495,24 +495,23 @@ impl ToPrimitive for BigUint { #[cfg(target_word_size = "32")] #[inline] fn to_u64(&self) -> Option<u64> { - match self.data { - [] => { - Some(0) + match self.data.len() { + 0 => Some(0), + 1 => Some(self.data[0] as u64), + 2 => { + Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64) } - [n0] => { - Some(n0 as u64) - } - [n0, n1] => { - Some(BigDigit::to_uint(n1, n0) as u64) - } - [n0, n1, n2] => { - let n_lo = BigDigit::to_uint(n1, n0) as u64; - let n_hi = n2 as u64; + 3 => { + let n_lo = BigDigit::to_uint(self.data[1], self.data[0]) as + u64; + let n_hi = self.data[2] as u64; Some((n_hi << 32) + n_lo) } - [n0, n1, n2, n3] => { - let n_lo = BigDigit::to_uint(n1, n0) as u64; - let n_hi = BigDigit::to_uint(n3, n2) as u64; + 4 => { + let n_lo = BigDigit::to_uint(self.data[1], self.data[0]) + as u64; + let n_hi = BigDigit::to_uint(self.data[3], self.data[2]) + as u64; Some((n_hi << 32) + n_lo) } _ => None @@ -522,16 +521,10 @@ impl ToPrimitive for BigUint { #[cfg(target_word_size = "64")] #[inline] fn to_u64(&self) -> Option<u64> { - match self.data { - [] => { - Some(0) - } - [n0] => { - Some(n0 as u64) - } - [n0, n1] => { - Some(BigDigit::to_uint(n1, n0) as u64) - } + match self.data.len() { + 0 => Some(0), + 1 => Some(self.data[0] as u64), + 2 => Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64), _ => None } } |
