Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SmallVec to avoid allocations in from_decimal_string. #55816

Merged
merged 1 commit into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2095,6 +2095,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]]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_apfloat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
13 changes: 7 additions & 6 deletions src/librustc_apfloat/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_apfloat/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ extern crate rustc_cratesio_shim;

#[macro_use]
extern crate bitflags;
extern crate smallvec;

use std::cmp::Ordering;
use std::fmt;
Expand Down