Skip to content

Commit e8a3934

Browse files
authored
Rollup merge of rust-lang#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%.
2 parents 5b0b0ce + a66d7b2 commit e8a3934

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,7 @@ version = "0.0.0"
20962096
dependencies = [
20972097
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
20982098
"rustc_cratesio_shim 0.0.0",
2099+
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
20992100
]
21002101

21012102
[[package]]

src/librustc_apfloat/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ path = "lib.rs"
1010
[dependencies]
1111
bitflags = "1.0"
1212
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
13+
smallvec = { version = "0.6.5", features = ["union"] }

src/librustc_apfloat/ieee.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use {Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
1212
use {Float, FloatConvert, ParseError, Round, Status, StatusAnd};
1313

14+
use smallvec::{SmallVec, smallvec};
1415
use std::cmp::{self, Ordering};
1516
use std::convert::TryFrom;
1617
use std::fmt::{self, Write};
@@ -1962,7 +1963,7 @@ impl<S: Semantics> IeeeFloat<S> {
19621963
// to hold the full significand, and an extra limb required by
19631964
// tcMultiplyPart.
19641965
let max_limbs = limbs_for_bits(1 + 196 * significand_digits / 59);
1965-
let mut dec_sig = Vec::with_capacity(max_limbs);
1966+
let mut dec_sig: SmallVec<[Limb; 1]> = SmallVec::with_capacity(max_limbs);
19661967

19671968
// Convert to binary efficiently - we do almost all multiplication
19681969
// in a Limb. When this would overflow do we do a single
@@ -2021,11 +2022,11 @@ impl<S: Semantics> IeeeFloat<S> {
20212022

20222023
const FIRST_EIGHT_POWERS: [Limb; 8] = [1, 5, 25, 125, 625, 3125, 15625, 78125];
20232024

2024-
let mut p5_scratch = vec![];
2025-
let mut p5 = vec![FIRST_EIGHT_POWERS[4]];
2025+
let mut p5_scratch = smallvec![];
2026+
let mut p5: SmallVec<[Limb; 1]> = smallvec![FIRST_EIGHT_POWERS[4]];
20262027

2027-
let mut r_scratch = vec![];
2028-
let mut r = vec![FIRST_EIGHT_POWERS[power & 7]];
2028+
let mut r_scratch = smallvec![];
2029+
let mut r: SmallVec<[Limb; 1]> = smallvec![FIRST_EIGHT_POWERS[power & 7]];
20292030
power >>= 3;
20302031

20312032
while power > 0 {
@@ -2064,7 +2065,7 @@ impl<S: Semantics> IeeeFloat<S> {
20642065
let calc_precision = (LIMB_BITS << attempt) - 1;
20652066
attempt += 1;
20662067

2067-
let calc_normal_from_limbs = |sig: &mut Vec<Limb>,
2068+
let calc_normal_from_limbs = |sig: &mut SmallVec<[Limb; 1]>,
20682069
limbs: &[Limb]|
20692070
-> StatusAnd<ExpInt> {
20702071
sig.resize(limbs_for_bits(calc_precision), 0);

src/librustc_apfloat/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern crate rustc_cratesio_shim;
5353

5454
#[macro_use]
5555
extern crate bitflags;
56+
extern crate smallvec;
5657

5758
use std::cmp::Ordering;
5859
use std::fmt;

0 commit comments

Comments
 (0)