diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2018-11-11 00:21:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-11 00:21:20 +0100 |
| commit | e8a3934599bbb2dbd285c6259cac71f70c1ec3e6 (patch) | |
| tree | a300012074f6b9f089ec0f18a7d483943124aa45 | |
| parent | 5b0b0ce61ebf0da19d89f1be7ccea67f6cd128a7 (diff) | |
| parent | a66d7b2001def5ab87e99d661e31890660f38374 (diff) | |
| download | rust-e8a3934599bbb2dbd285c6259cac71f70c1ec3e6.tar.gz rust-e8a3934599bbb2dbd285c6259cac71f70c1ec3e6.zip | |
Rollup merge of #55816 - nnethercote:from_decimal_string-SmallVec, r=oli-obk
Use `SmallVec` to avoid allocations in `from_decimal_string`. This reduces the number of allocations in a "check clean" build of `tuple-stress` by 14%, reducing instruction counts by 0.6%.
| -rw-r--r-- | src/Cargo.lock | 1 | ||||
| -rw-r--r-- | src/librustc_apfloat/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustc_apfloat/ieee.rs | 13 | ||||
| -rw-r--r-- | src/librustc_apfloat/lib.rs | 1 |
4 files changed, 10 insertions, 6 deletions
diff --git a/src/Cargo.lock b/src/Cargo.lock index 4db9801e01d..2ac51263cb5 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -2096,6 +2096,7 @@ version = "0.0.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_cratesio_shim 0.0.0", + "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/src/librustc_apfloat/Cargo.toml b/src/librustc_apfloat/Cargo.toml index 735b74f1565..a8a5da90c7a 100644 --- a/src/librustc_apfloat/Cargo.toml +++ b/src/librustc_apfloat/Cargo.toml @@ -10,3 +10,4 @@ path = "lib.rs" [dependencies] bitflags = "1.0" rustc_cratesio_shim = { path = "../librustc_cratesio_shim" } +smallvec = { version = "0.6.5", features = ["union"] } diff --git a/src/librustc_apfloat/ieee.rs b/src/librustc_apfloat/ieee.rs index 87d59d2e763..4f405858e35 100644 --- a/src/librustc_apfloat/ieee.rs +++ b/src/librustc_apfloat/ieee.rs @@ -11,6 +11,7 @@ use {Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO}; use {Float, FloatConvert, ParseError, Round, Status, StatusAnd}; +use smallvec::{SmallVec, smallvec}; use std::cmp::{self, Ordering}; use std::convert::TryFrom; use std::fmt::{self, Write}; @@ -1962,7 +1963,7 @@ impl<S: Semantics> IeeeFloat<S> { // to hold the full significand, and an extra limb required by // tcMultiplyPart. let max_limbs = limbs_for_bits(1 + 196 * significand_digits / 59); - let mut dec_sig = Vec::with_capacity(max_limbs); + let mut dec_sig: SmallVec<[Limb; 1]> = SmallVec::with_capacity(max_limbs); // Convert to binary efficiently - we do almost all multiplication // in a Limb. When this would overflow do we do a single @@ -2021,11 +2022,11 @@ impl<S: Semantics> IeeeFloat<S> { const FIRST_EIGHT_POWERS: [Limb; 8] = [1, 5, 25, 125, 625, 3125, 15625, 78125]; - let mut p5_scratch = vec![]; - let mut p5 = vec![FIRST_EIGHT_POWERS[4]]; + let mut p5_scratch = smallvec![]; + let mut p5: SmallVec<[Limb; 1]> = smallvec![FIRST_EIGHT_POWERS[4]]; - let mut r_scratch = vec![]; - let mut r = vec![FIRST_EIGHT_POWERS[power & 7]]; + let mut r_scratch = smallvec![]; + let mut r: SmallVec<[Limb; 1]> = smallvec![FIRST_EIGHT_POWERS[power & 7]]; power >>= 3; while power > 0 { @@ -2064,7 +2065,7 @@ impl<S: Semantics> IeeeFloat<S> { let calc_precision = (LIMB_BITS << attempt) - 1; attempt += 1; - let calc_normal_from_limbs = |sig: &mut Vec<Limb>, + let calc_normal_from_limbs = |sig: &mut SmallVec<[Limb; 1]>, limbs: &[Limb]| -> StatusAnd<ExpInt> { sig.resize(limbs_for_bits(calc_precision), 0); diff --git a/src/librustc_apfloat/lib.rs b/src/librustc_apfloat/lib.rs index 6ea722ba769..69c9f385409 100644 --- a/src/librustc_apfloat/lib.rs +++ b/src/librustc_apfloat/lib.rs @@ -53,6 +53,7 @@ extern crate rustc_cratesio_shim; #[macro_use] extern crate bitflags; +extern crate smallvec; use std::cmp::Ordering; use std::fmt; |
