Skip to content

Commit

Permalink
Run rustfmt on the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
myrrlyn committed Jan 23, 2020
1 parent c4013af commit e223a43
Show file tree
Hide file tree
Showing 39 changed files with 3,584 additions and 1,536 deletions.
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ that do not immediately touch the codebase, you can reach me informally to talk
about them or open an issue.

I will do my best to respond to all contacts in a timely manner.

## Environment

This project is formatted with the following command:

```sh
cargo +nightly fmt -- --config-path rustfmt-nightly.toml
```

A smaller `rustfmt.toml` is provided which is capable of being executed by the
pinned stable `rustfmt`; however, as `rustfmt` is an unstable tool, the nightly
formatter is used to handle more complex configuration.

Please ensure that you run this formatter before sending in a PR, in order to
avoid excessive noise.
22 changes: 13 additions & 9 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ check:
cargo check --all-features

# Runs all of the recipes necessary for pre-publish.
checkout: check clippy build doc test package
checkout: format check lint build doc test package

# Continually runs the development routines.
ci:
Expand All @@ -30,19 +30,23 @@ ci:
clean:
cargo clean

# Runs clippy.
clippy: check
cargo clippy --no-default-features
cargo clippy --no-default-features --features alloc
cargo clippy --all-features

# Runs the development routines.
dev: clippy doc test
dev: format lint doc test

# Builds the crate documentation.
doc:
cargo doc --all-features --document-private-items

# Runs the formatter on all Rust files.
format:
cargo +nightly fmt -- --config-path rustfmt-nightly.toml

# Runs the linter.
lint: check
cargo clippy --no-default-features
cargo clippy --no-default-features --features alloc
cargo clippy --all-features

# Continually runs some recipe from this file.
loop action:
cargo watch -s "just {{action}}"
Expand All @@ -59,7 +63,7 @@ publish: checkout
cargo publish

# Runs the test suites.
test: check clippy
test: check lint
cargo test --no-default-features
cargo test --all-features
cargo run --all-features --example ipv4
Expand Down
146 changes: 77 additions & 69 deletions benches/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,92 +17,100 @@ within 20ns.

extern crate test;

use test::Bencher;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, 1, 0, 1, 1, 0, 1,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 1, 1, 0, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 0, 1, 0, 0, 0, 0, 1,
]
});
}

#[bench]
Expand Down
84 changes: 39 additions & 45 deletions benches/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use core::ops::AddAssign;

use bitvec::prelude::*;
use test::{
Bencher,
bench::black_box,
Bencher,
};

/* `BitSlice::empty` is not benched, because the compiler const-folds it. It
Expand All @@ -26,11 +26,10 @@ fn element(b: &mut Bencher) {
b.iter(|| BitSlice::<Msb0, u32>::from_element(&!0));
b.iter(|| BitSlice::<Lsb0, u32>::from_element(&!0));

#[cfg(target_pointer_width = "64")] {

b.iter(|| BitSlice::<Msb0, u64>::from_element(&!0));
b.iter(|| BitSlice::<Lsb0, u64>::from_element(&!0));

#[cfg(target_pointer_width = "64")]
{
b.iter(|| BitSlice::<Msb0, u64>::from_element(&!0));
b.iter(|| BitSlice::<Lsb0, u64>::from_element(&!0));
}
}

Expand All @@ -43,11 +42,10 @@ fn slice(b: &mut Bencher) {
b.iter(|| BitSlice::<Msb0, u32>::from_slice(&[0, 1, !0 - 1, !0][..]));
b.iter(|| BitSlice::<Lsb0, u32>::from_slice(&[0, 1, !0 - 1, !0][..]));

#[cfg(target_pointer_width = "64")] {

b.iter(|| BitSlice::<Msb0, u64>::from_slice(&[0, 1, !0 - 1, !0][..]));
b.iter(|| BitSlice::<Lsb0, u64>::from_slice(&[0, 1, !0 - 1, !0][..]));

#[cfg(target_pointer_width = "64")]
{
b.iter(|| BitSlice::<Msb0, u64>::from_slice(&[0, 1, !0 - 1, !0][..]));
b.iter(|| BitSlice::<Lsb0, u64>::from_slice(&[0, 1, !0 - 1, !0][..]));
}
}

Expand All @@ -68,13 +66,12 @@ fn len(b: &mut Bencher) {
b.iter(|| bsb32.len());
b.iter(|| bsl32.len());

#[cfg(target_pointer_width = "64")] {

let bsb64 = [0u64; 2].bits::<Msb0>();
let bsl64 = [0u64; 2].bits::<Lsb0>();
b.iter(|| bsb64.len());
b.iter(|| bsl64.len());

#[cfg(target_pointer_width = "64")]
{
let bsb64 = [0u64; 2].bits::<Msb0>();
let bsl64 = [0u64; 2].bits::<Lsb0>();
b.iter(|| bsb64.len());
b.iter(|| bsl64.len());
}
}

Expand All @@ -97,13 +94,12 @@ fn index(b: &mut Bencher) {
b.iter(|| assert!(!black_box(bsb32)[black_box(69)]));
b.iter(|| assert!(!black_box(bsl32)[black_box(69)]));

#[cfg(target_pointer_width = "64")] {

let bsb64 = [0u64; 2].bits::<Msb0>();
let bsl64 = [0u64; 2].bits::<Lsb0>();
b.iter(|| assert!(!black_box(bsb64)[black_box(69)]));
b.iter(|| assert!(!black_box(bsl64)[black_box(69)]));

#[cfg(target_pointer_width = "64")]
{
let bsb64 = [0u64; 2].bits::<Msb0>();
let bsl64 = [0u64; 2].bits::<Lsb0>();
b.iter(|| assert!(!black_box(bsb64)[black_box(69)]));
b.iter(|| assert!(!black_box(bsl64)[black_box(69)]));
}
}

Expand Down Expand Up @@ -133,15 +129,14 @@ fn get_mut(b: &mut Bencher) {
let bsl32 = src.bits_mut::<Lsb0>();
b.iter(|| *bsl32.get_mut(69).unwrap() = true);

#[cfg(target_pointer_width = "64")] {

let mut src = [0u64; 2];
let bsb64 = src.bits_mut::<Msb0>();
b.iter(|| *bsb64.get_mut(69).unwrap() = true);
let mut src = [0u64; 2];
let bsl64 = src.bits_mut::<Lsb0>();
b.iter(|| *bsl64.get_mut(69).unwrap() = true);

#[cfg(target_pointer_width = "64")]
{
let mut src = [0u64; 2];
let bsb64 = src.bits_mut::<Msb0>();
b.iter(|| *bsb64.get_mut(69).unwrap() = true);
let mut src = [0u64; 2];
let bsl64 = src.bits_mut::<Lsb0>();
b.iter(|| *bsl64.get_mut(69).unwrap() = true);
}
}

Expand Down Expand Up @@ -174,16 +169,15 @@ fn add_assign(b: &mut Bencher) {
b.iter(|| bsb32a.add_assign(bsb32b.iter().copied()));
b.iter(|| bsl32a.add_assign(bsl32b.iter().copied()));

#[cfg(target_pointer_width = "64")] {

let mut src = [0u64; 2];
let bsb64a = src.bits_mut::<Msb0>();
let bsb64b = [0u64; 2].bits::<Msb0>();
let mut src = [0u64; 2];
let bsl64a = src.bits_mut::<Lsb0>();
let bsl64b = [0u64; 2].bits::<Lsb0>();
b.iter(|| bsb64a.add_assign(bsb64b.iter().copied()));
b.iter(|| bsl64a.add_assign(bsl64b.iter().copied()));

#[cfg(target_pointer_width = "64")]
{
let mut src = [0u64; 2];
let bsb64a = src.bits_mut::<Msb0>();
let bsb64b = [0u64; 2].bits::<Msb0>();
let mut src = [0u64; 2];
let bsl64a = src.bits_mut::<Lsb0>();
let bsl64b = [0u64; 2].bits::<Lsb0>();
b.iter(|| bsb64a.add_assign(bsb64b.iter().copied()));
b.iter(|| bsl64a.add_assign(bsl64b.iter().copied()));
}
}

0 comments on commit e223a43

Please sign in to comment.