Skip to content
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
3 changes: 2 additions & 1 deletion ethbloom/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog

The format is based on [Keep a Changelog].
The format is based on [Keep a Changelog].

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317)

## [0.8.1] - 2019-10-24
### Dependencies
Expand Down
3 changes: 1 addition & 2 deletions ethbloom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ rand = "0.7.2"
hex-literal = "0.2.1"

[features]
default = ["std", "serialize", "libc", "rustc-hex"]
default = ["std", "serialize", "rustc-hex"]
std = ["fixed-hash/std", "crunchy/std"]
serialize = ["std", "impl-serde"]
libc = ["fixed-hash/libc"]
rustc-hex = ["fixed-hash/rustc-hex"]

[[bench]]
Expand Down
5 changes: 3 additions & 2 deletions fixed-hash/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# Changelog

The format is based on [Keep a Changelog].
The format is based on [Keep a Changelog].

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317)

## [0.5.2] - 2019-12-19
### Fixed
- re-export `alloc` for both std and no-std to fix compilation (See [PR #268](https://github.com/paritytech/parity-common/pull/268))
- re-export `alloc` for both std and no-std to fix compilation (See [PR #268](https://github.com/paritytech/parity-common/pull/268))

## [0.5.1] - 2019-10-24
### Dependencies
Expand Down
10 changes: 6 additions & 4 deletions fixed-hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ static_assertions = "1.0.0"

[dev-dependencies]
rand_xorshift = "0.2.0"

[target.'cfg(not(target_os = "unknown"))'.dependencies]
libc = { version = "0.2.65", optional = true, default-features = false }
criterion = "0.3.0"

[features]
default = ["std", "libc", "rand", "rustc-hex", "byteorder"]
default = ["std", "rand", "rustc-hex", "byteorder"]
std = ["rustc-hex/std", "rand/std", "byteorder/std"]

api-dummy = [] # Feature used by docs.rs to display documentation of hash types

[[bench]]
name = "cmp"
harness = false
98 changes: 98 additions & 0 deletions fixed-hash/benches/cmp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright 2020 Parity Technologies
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Benchmarks for fixed-hash cmp implementation.

use criterion::{black_box, Criterion, ParameterizedBenchmark};
use criterion::{criterion_group, criterion_main};

use fixed_hash::construct_fixed_hash;

construct_fixed_hash! { pub struct H256(32); }

criterion_group!(cmp, eq_equal, eq_nonequal, compare,);
criterion_main!(cmp);

fn eq_equal(c: &mut Criterion) {
c.bench(
"eq_equal",
ParameterizedBenchmark::new(
"",
|b, x| b.iter(|| black_box(x.eq(black_box(x)))),
vec![
H256::zero(),
H256::repeat_byte(0xAA),
H256::from([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19,
0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06,
]),
H256([u8::max_value(); 32]),
],
),
);
}

fn eq_nonequal(c: &mut Criterion) {
c.bench(
"eq_nonequal",
ParameterizedBenchmark::new(
"",
|b, (x, y)| b.iter(|| black_box(x.eq(black_box(y)))),
vec![
(
H256::zero(),
H256::from([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
]),
),
(H256::repeat_byte(0xAA), H256::repeat_byte(0xA1)),
(
H256::from([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19,
0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06,
]),
H256::from([
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19,
0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06,
]),
),
],
),
);
}

fn compare(c: &mut Criterion) {
c.bench(
"compare",
ParameterizedBenchmark::new(
"",
|b, (x, y)| b.iter(|| black_box(x.cmp(black_box(y)))),
vec![
(
H256::zero(),
H256::from([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
]),
),
(H256::zero(), H256::zero()),
(H256::repeat_byte(0xAA), H256::repeat_byte(0xAA)),
(H256::repeat_byte(0xAA), H256::repeat_byte(0xA1)),
(
H256::from([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19,
0x40, 0x84, 0xC2, 0xDF, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06,
]),
H256::from([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEF, 0x2D, 0x6D, 0x19,
0x40, 0x84, 0xC2, 0xDE, 0x36, 0xE0, 0xDA, 0xBF, 0xCE, 0x45, 0xD0, 0x46, 0xB3, 0x7D, 0x11, 0x06,
]),
),
],
),
);
}
58 changes: 2 additions & 56 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ macro_rules! construct_fixed_hash {

impl_byteorder_for_fixed_hash!($name);
impl_rand_for_fixed_hash!($name);
impl_libc_for_fixed_hash!($name);
impl_cmp_for_fixed_hash!($name);
impl_rustc_hex_for_fixed_hash!($name);
impl_quickcheck_for_fixed_hash!($name);
}
Expand Down Expand Up @@ -527,17 +527,9 @@ macro_rules! impl_rand_for_fixed_hash {
};
}

// Implementation for disabled libc crate support.
//
// # Note
//
// Feature guarded macro definitions instead of feature guarded impl blocks
// to work around the problems of introducing `libc` crate feature in
// a user crate.
#[cfg(not(all(feature = "libc", not(target_os = "unknown"))))]
#[macro_export]
#[doc(hidden)]
macro_rules! impl_libc_for_fixed_hash {
macro_rules! impl_cmp_for_fixed_hash {
( $name:ident ) => {
impl $crate::core_::cmp::PartialEq for $name {
#[inline]
Expand All @@ -555,52 +547,6 @@ macro_rules! impl_libc_for_fixed_hash {
};
}

// Implementation for enabled libc crate support.
//
// # Note
//
// Feature guarded macro definitions instead of feature guarded impl blocks
// to work around the problems of introducing `libc` crate feature in
// a user crate.
#[cfg(all(feature = "libc", not(target_os = "unknown")))]
#[macro_export]
#[doc(hidden)]
macro_rules! impl_libc_for_fixed_hash {
( $name:ident ) => {
impl $crate::core_::cmp::PartialEq for $name {
#[inline]
fn eq(&self, other: &Self) -> bool {
unsafe {
$crate::libc::memcmp(
self.as_ptr() as *const $crate::libc::c_void,
other.as_ptr() as *const $crate::libc::c_void,
Self::len_bytes(),
) == 0
}
}
}

impl $crate::core_::cmp::Ord for $name {
fn cmp(&self, other: &Self) -> $crate::core_::cmp::Ordering {
let r = unsafe {
$crate::libc::memcmp(
self.as_ptr() as *const $crate::libc::c_void,
other.as_ptr() as *const $crate::libc::c_void,
Self::len_bytes(),
)
};
if r < 0 {
return $crate::core_::cmp::Ordering::Less;
}
if r > 0 {
return $crate::core_::cmp::Ordering::Greater;
}
$crate::core_::cmp::Ordering::Equal
}
}
};
}

// Implementation for disabled rustc-hex crate support.
//
// # Note
Expand Down
1 change: 1 addition & 0 deletions primitive-types/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog].
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
- Removed `libc` feature. [#317](https://github.com/paritytech/parity-common/pull/317)

## [0.6.2] - 2019-01-03
- Expose to_hex and from_hex from impl-serde. [#302](https://github.com/paritytech/parity-common/pull/302)
Expand Down
1 change: 0 additions & 1 deletion primitive-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ impl-rlp = { version = "0.2", path = "impls/rlp", default-features = false, opti
default = ["std"]
std = ["uint/std", "fixed-hash/std", "impl-codec/std"]
byteorder = ["fixed-hash/byteorder"]
libc = ["fixed-hash/libc"]
rustc-hex = ["fixed-hash/rustc-hex"]
serde = ["std", "impl-serde"]
codec = ["impl-codec"]
Expand Down