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

Simplify/remove build.rs following the bump to 2021 edition #1062

Merged
merged 7 commits into from
Sep 11, 2023
Merged
54 changes: 0 additions & 54 deletions build.rs

This file was deleted.

86 changes: 61 additions & 25 deletions src/lexical/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//! buffers, so for a `vec![0, 1, 2, 3]`, `3` is the most significant limb,
//! and `0` is the least significant limb.

use super::large_powers;
use super::num::*;
use super::small_powers::*;
use alloc::vec::Vec;
Expand Down Expand Up @@ -36,31 +35,58 @@ use core::{cmp, iter, mem};
// requiring software emulation.
// sparc64 (`UMUL` only supported double-word arguments).

// 32-BIT LIMB
#[cfg(limb_width_32)]
pub type Limb = u32;

#[cfg(limb_width_32)]
pub const POW5_LIMB: &[Limb] = &POW5_32;

#[cfg(limb_width_32)]
pub const POW10_LIMB: &[Limb] = &POW10_32;
#[doc(hidden)]
pub trait LimbConfig {
type Limb: 'static;
type Wide: 'static;
const POW5_LIMB: &'static [Self::Limb];
const POW10_LIMB: &'static [Self::Limb];
const LARGE_POWERS: &'static [&'static [Self::Limb]];
}

#[cfg(limb_width_32)]
type Wide = u64;
// 32-BIT LIMB
#[doc(hidden)]
pub struct LimbConfig32;

impl LimbConfig for LimbConfig32 {
type Limb = u32;
type Wide = u64;
const POW5_LIMB: &'static [Self::Limb] = &POW5_32;
const POW10_LIMB: &'static [Self::Limb] = &POW10_32;
const LARGE_POWERS: &'static [&'static [Self::Limb]] = &super::large_powers32::POW5;
}

// 64-BIT LIMB
#[cfg(limb_width_64)]
pub type Limb = u64;

#[cfg(limb_width_64)]
pub const POW5_LIMB: &[Limb] = &POW5_64;

#[cfg(limb_width_64)]
pub const POW10_LIMB: &[Limb] = &POW10_64;
#[doc(hidden)]
pub struct LimbConfig64;
impl LimbConfig for LimbConfig64 {
type Limb = u64;
type Wide = u128;
const POW5_LIMB: &'static [Self::Limb] = &POW5_64;
const POW10_LIMB: &'static [Self::Limb] = &POW10_64;
const LARGE_POWERS: &'static [&'static [Self::Limb]] = &super::large_powers64::POW5;
}

#[cfg(limb_width_64)]
type Wide = u128;
#[cfg(any(
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "powerpc64",
target_arch = "x86_64"
))]
type PlatformLimbConfig = LimbConfig64;
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "powerpc64",
target_arch = "x86_64"
)))]
type PlatformLimbConfig = LimbConfig32;

pub type Limb = <PlatformLimbConfig as LimbConfig>::Limb;
type Wide = <PlatformLimbConfig as LimbConfig>::Wide;
pub const POW5_LIMB: &[Limb] = PlatformLimbConfig::POW5_LIMB;
pub const POW10_LIMB: &[Limb] = PlatformLimbConfig::POW10_LIMB;
const LARGE_POWERS: &'static [&'static [Limb]] = PlatformLimbConfig::LARGE_POWERS;

/// Cast to limb type.
#[inline]
Expand All @@ -79,14 +105,24 @@ fn as_wide<T: Integer>(t: T) -> Wide {

/// Split u64 into limbs, in little-endian order.
#[inline]
#[cfg(limb_width_32)]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "powerpc64",
target_arch = "x86_64"
)))]
fn split_u64(x: u64) -> [Limb; 2] {
[as_limb(x), as_limb(x >> 32)]
}

/// Split u64 into limbs, in little-endian order.
#[inline]
#[cfg(limb_width_64)]
#[cfg(any(
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "powerpc64",
target_arch = "x86_64"
))]
fn split_u64(x: u64) -> [Limb; 1] {
[as_limb(x)]
}
Expand Down Expand Up @@ -391,7 +427,7 @@ mod small {
use super::large::KARATSUBA_CUTOFF;

let small_powers = POW5_LIMB;
let large_powers = large_powers::POW5;
let large_powers = LARGE_POWERS;

if n == 0 {
// No exponent, just return.
Expand Down
9 changes: 2 additions & 7 deletions src/lexical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@ mod digit;
mod errors;
pub(crate) mod exponent;
pub(crate) mod float;
mod large_powers;
mod large_powers32;
mod large_powers64;
pub(crate) mod math;
pub(crate) mod num;
pub(crate) mod parse;
pub(crate) mod rounding;
mod shift;
mod small_powers;

#[cfg(limb_width_32)]
mod large_powers32;

#[cfg(limb_width_64)]
mod large_powers64;

// API
pub use self::parse::{parse_concise_float, parse_truncated_float};
3 changes: 0 additions & 3 deletions src/lexical/small_powers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
//! Pre-computed small powers.

// 32 BIT
#[cfg(limb_width_32)]
pub(crate) const POW5_32: [u32; 14] = [
1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, 48828125, 244140625,
1220703125,
];

#[cfg(limb_width_32)]
pub(crate) const POW10_32: [u32; 10] = [
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000,
];

// 64 BIT
#[cfg(limb_width_64)]
pub(crate) const POW5_64: [u64; 28] = [
1,
5,
Expand Down
39 changes: 0 additions & 39 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl Map<String, Value> {
/// The key may be any borrowed form of the map's key type, but the ordering
/// on the borrowed form *must* match the ordering on the key type.
#[inline]
#[cfg(any(feature = "preserve_order", not(no_btreemap_get_key_value)))]
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
where
String: Borrow<Q>,
Expand Down Expand Up @@ -153,44 +152,7 @@ impl Map<String, Value> {
String: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
{
#[cfg(any(feature = "preserve_order", not(no_btreemap_remove_entry)))]
return self.map.remove_entry(key);
osiewicz marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(all(
not(feature = "preserve_order"),
no_btreemap_remove_entry,
not(no_btreemap_get_key_value),
))]
{
let (key, _value) = self.map.get_key_value(key)?;
let key = key.clone();
let value = self.map.remove::<String>(&key)?;
Some((key, value))
}
#[cfg(all(
not(feature = "preserve_order"),
no_btreemap_remove_entry,
no_btreemap_get_key_value,
))]
{
use core::ops::{Bound, RangeBounds};

struct Key<'a, Q: ?Sized>(&'a Q);

impl<'a, Q: ?Sized> RangeBounds<Q> for Key<'a, Q> {
fn start_bound(&self) -> Bound<&Q> {
Bound::Included(self.0)
}
fn end_bound(&self) -> Bound<&Q> {
Bound::Included(self.0)
}
}

let mut range = self.map.range(Key(key));
let (key, _value) = range.next()?;
let key = key.clone();
let value = self.map.remove::<String>(&key)?;
Some((key, value))
}
}

/// Moves all elements from other into self, leaving other empty.
Expand Down Expand Up @@ -276,7 +238,6 @@ impl Map<String, Value> {
///
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)`
/// returns `false`.
#[cfg(not(no_btreemap_retain))]
#[inline]
pub fn retain<F>(&mut self, f: F)
where
Expand Down
14 changes: 12 additions & 2 deletions tests/lexical/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ impl Math for Bigint {
}
}

#[cfg(limb_width_32)]
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "powerpc64",
target_arch = "x86_64"
)))]
pub(crate) fn from_u32(x: &[u32]) -> Vec<Limb> {
x.iter().cloned().collect()
}

#[cfg(limb_width_64)]
#[cfg(any(
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "powerpc64",
target_arch = "x86_64"
))]
pub(crate) fn from_u32(x: &[u32]) -> Vec<Limb> {
let mut v = Vec::<Limb>::default();
for xi in x.chunks(2) {
Expand Down
1 change: 0 additions & 1 deletion tests/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fn test_append() {
assert!(val.is_empty());
}

#[cfg(not(no_btreemap_retain))]
#[test]
fn test_retain() {
let mut v: Value = from_str(r#"{"b":null,"a":null,"c":null}"#).unwrap();
Expand Down