Skip to content

Commit

Permalink
style: use rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Feb 8, 2020
1 parent b1486da commit f86396e
Show file tree
Hide file tree
Showing 5 changed files with 1,286 additions and 486 deletions.
200 changes: 116 additions & 84 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ extern crate rand;
extern crate test;

macro_rules! bench_num {
($name:ident, $read:ident, $bytes:expr, $data:expr) => (
($name:ident, $read:ident, $bytes:expr, $data:expr) => {
mod $name {
use byteorder::{ByteOrder, BigEndian, NativeEndian, LittleEndian};
use super::test::Bencher;
use super::test::black_box as bb;
use super::test::Bencher;
use byteorder::{
BigEndian, ByteOrder, LittleEndian, NativeEndian,
};

const NITER: usize = 100_000;

Expand Down Expand Up @@ -43,14 +45,16 @@ macro_rules! bench_num {
});
}
}
);
};
($ty:ident, $max:ident,
$read:ident, $write:ident, $size:expr, $data:expr) => (
$read:ident, $write:ident, $size:expr, $data:expr) => {
mod $ty {
use std::$ty;
use byteorder::{ByteOrder, BigEndian, NativeEndian, LittleEndian};
use super::test::Bencher;
use super::test::black_box as bb;
use super::test::Bencher;
use byteorder::{
BigEndian, ByteOrder, LittleEndian, NativeEndian,
};
use std::$ty;

const NITER: usize = 100_000;

Expand Down Expand Up @@ -117,7 +121,7 @@ macro_rules! bench_num {
});
}
}
);
};
}

bench_num!(u16, MAX, read_u16, write_u16, 2, [1, 2]);
Expand All @@ -127,8 +131,7 @@ bench_num!(i32, MAX, read_i32, write_i32, 4, [1, 2, 3, 4]);
bench_num!(u64, MAX, read_u64, write_u64, 8, [1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(i64, MAX, read_i64, write_i64, 8, [1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(f32, MAX, read_f32, write_f32, 4, [1, 2, 3, 4]);
bench_num!(f64, MAX, read_f64, write_f64, 8,
[1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(f64, MAX, read_f64, write_f64, 8, [1, 2, 3, 4, 5, 6, 7, 8]);

bench_num!(uint_1, read_uint, 1, [1]);
bench_num!(uint_2, read_uint, 2, [1, 2]);
Expand All @@ -149,119 +152,148 @@ bench_num!(int_7, read_int, 7, [1, 2, 3, 4, 5, 6, 7]);
bench_num!(int_8, read_int, 8, [1, 2, 3, 4, 5, 6, 7, 8]);

#[cfg(byteorder_i128)]
bench_num!(u128, MAX, read_u128, write_u128,
16, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
#[cfg(byteorder_i128)]
bench_num!(i128, MAX, read_i128, write_i128,
16, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
bench_num!(
u128,
MAX,
read_u128,
write_u128,
16,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
);
#[cfg(byteorder_i128)]
bench_num!(
i128,
MAX,
read_i128,
write_i128,
16,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
);

#[cfg(byteorder_i128)]
bench_num!(uint128_1, read_uint128,
1, [1]);
bench_num!(uint128_1, read_uint128, 1, [1]);
#[cfg(byteorder_i128)]
bench_num!(uint128_2, read_uint128,
2, [1, 2]);
bench_num!(uint128_2, read_uint128, 2, [1, 2]);
#[cfg(byteorder_i128)]
bench_num!(uint128_3, read_uint128,
3, [1, 2, 3]);
bench_num!(uint128_3, read_uint128, 3, [1, 2, 3]);
#[cfg(byteorder_i128)]
bench_num!(uint128_4, read_uint128,
4, [1, 2, 3, 4]);
bench_num!(uint128_4, read_uint128, 4, [1, 2, 3, 4]);
#[cfg(byteorder_i128)]
bench_num!(uint128_5, read_uint128,
5, [1, 2, 3, 4, 5]);
bench_num!(uint128_5, read_uint128, 5, [1, 2, 3, 4, 5]);
#[cfg(byteorder_i128)]
bench_num!(uint128_6, read_uint128,
6, [1, 2, 3, 4, 5, 6]);
bench_num!(uint128_6, read_uint128, 6, [1, 2, 3, 4, 5, 6]);
#[cfg(byteorder_i128)]
bench_num!(uint128_7, read_uint128,
7, [1, 2, 3, 4, 5, 6, 7]);
bench_num!(uint128_7, read_uint128, 7, [1, 2, 3, 4, 5, 6, 7]);
#[cfg(byteorder_i128)]
bench_num!(uint128_8, read_uint128,
8, [1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(uint128_8, read_uint128, 8, [1, 2, 3, 4, 5, 6, 7, 8]);
#[cfg(byteorder_i128)]
bench_num!(uint128_9, read_uint128,
9, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
bench_num!(uint128_9, read_uint128, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
#[cfg(byteorder_i128)]
bench_num!(uint128_10, read_uint128,
10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
bench_num!(uint128_10, read_uint128, 10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
#[cfg(byteorder_i128)]
bench_num!(uint128_11, read_uint128,
11, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
bench_num!(uint128_11, read_uint128, 11, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
#[cfg(byteorder_i128)]
bench_num!(uint128_12, read_uint128,
12, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
bench_num!(
uint128_12,
read_uint128,
12,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
);
#[cfg(byteorder_i128)]
bench_num!(uint128_13, read_uint128,
13, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
bench_num!(
uint128_13,
read_uint128,
13,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
);
#[cfg(byteorder_i128)]
bench_num!(uint128_14, read_uint128,
14, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]);
bench_num!(
uint128_14,
read_uint128,
14,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
);
#[cfg(byteorder_i128)]
bench_num!(uint128_15, read_uint128,
15, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
bench_num!(
uint128_15,
read_uint128,
15,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
);
#[cfg(byteorder_i128)]
bench_num!(uint128_16, read_uint128,
16, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
bench_num!(
uint128_16,
read_uint128,
16,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
);

#[cfg(byteorder_i128)]
bench_num!(int128_1, read_int128,
1, [1]);
bench_num!(int128_1, read_int128, 1, [1]);
#[cfg(byteorder_i128)]
bench_num!(int128_2, read_int128,
2, [1, 2]);
bench_num!(int128_2, read_int128, 2, [1, 2]);
#[cfg(byteorder_i128)]
bench_num!(int128_3, read_int128,
3, [1, 2, 3]);
bench_num!(int128_3, read_int128, 3, [1, 2, 3]);
#[cfg(byteorder_i128)]
bench_num!(int128_4, read_int128,
4, [1, 2, 3, 4]);
bench_num!(int128_4, read_int128, 4, [1, 2, 3, 4]);
#[cfg(byteorder_i128)]
bench_num!(int128_5, read_int128,
5, [1, 2, 3, 4, 5]);
bench_num!(int128_5, read_int128, 5, [1, 2, 3, 4, 5]);
#[cfg(byteorder_i128)]
bench_num!(int128_6, read_int128,
6, [1, 2, 3, 4, 5, 6]);
bench_num!(int128_6, read_int128, 6, [1, 2, 3, 4, 5, 6]);
#[cfg(byteorder_i128)]
bench_num!(int128_7, read_int128,
7, [1, 2, 3, 4, 5, 6, 7]);
bench_num!(int128_7, read_int128, 7, [1, 2, 3, 4, 5, 6, 7]);
#[cfg(byteorder_i128)]
bench_num!(int128_8, read_int128,
8, [1, 2, 3, 4, 5, 6, 7, 8]);
bench_num!(int128_8, read_int128, 8, [1, 2, 3, 4, 5, 6, 7, 8]);
#[cfg(byteorder_i128)]
bench_num!(int128_9, read_int128,
9, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
bench_num!(int128_9, read_int128, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
#[cfg(byteorder_i128)]
bench_num!(int128_10, read_int128,
10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
bench_num!(int128_10, read_int128, 10, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
#[cfg(byteorder_i128)]
bench_num!(int128_11, read_int128,
11, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
bench_num!(int128_11, read_int128, 11, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
#[cfg(byteorder_i128)]
bench_num!(int128_12, read_int128,
12, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
bench_num!(
int128_12,
read_int128,
12,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
);
#[cfg(byteorder_i128)]
bench_num!(int128_13, read_int128,
13, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
bench_num!(
int128_13,
read_int128,
13,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
);
#[cfg(byteorder_i128)]
bench_num!(int128_14, read_int128,
14, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]);
bench_num!(
int128_14,
read_int128,
14,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
);
#[cfg(byteorder_i128)]
bench_num!(int128_15, read_int128,
15, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
bench_num!(
int128_15,
read_int128,
15,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
);
#[cfg(byteorder_i128)]
bench_num!(int128_16, read_int128,
16, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);

bench_num!(
int128_16,
read_int128,
16,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
);

macro_rules! bench_slice {
($name:ident, $numty:ty, $read:ident, $write:ident) => {
mod $name {
use std::mem::size_of;

use byteorder::{ByteOrder, BigEndian, LittleEndian};
use rand::{self, Rng};
use byteorder::{BigEndian, ByteOrder, LittleEndian};
use rand::distributions;
use rand::{self, Rng};
use test::Bencher;

#[bench]
Expand Down Expand Up @@ -322,7 +354,7 @@ macro_rules! bench_slice {
});
}
}
}
};
}

bench_slice!(slice_u64, u64, read_u64_into, write_u64_into);
10 changes: 4 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ fn main() {
&mut io::stderr(),
"failed to parse `rustc --version`: {}",
err
).unwrap();
)
.unwrap();
return;
}
};
Expand All @@ -39,11 +40,8 @@ struct Version {
impl Version {
fn read() -> Result<Version, String> {
let rustc = env::var_os("RUSTC").unwrap_or(OsString::from("rustc"));
let output = Command::new(&rustc)
.arg("--version")
.output()
.unwrap()
.stdout;
let output =
Command::new(&rustc).arg("--version").output().unwrap().stdout;
Version::parse(&String::from_utf8(output).unwrap())
}

Expand Down
2 changes: 2 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
max_width = 79
use_small_heuristics = "max"
14 changes: 4 additions & 10 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,10 +903,7 @@ pub trait ReadBytesExt: io::Read {
/// assert_eq!([f32::consts::PI, 1.0], dst);
/// ```
#[inline]
fn read_f32_into<T: ByteOrder>(
&mut self,
dst: &mut [f32],
) -> Result<()> {
fn read_f32_into<T: ByteOrder>(&mut self, dst: &mut [f32]) -> Result<()> {
{
let buf = unsafe { slice_to_u8_mut(dst) };
try!(self.read_exact(buf));
Expand Down Expand Up @@ -951,7 +948,7 @@ pub trait ReadBytesExt: io::Read {
/// assert_eq!([f32::consts::PI, 1.0], dst);
/// ```
#[inline]
#[deprecated(since="1.2.0", note="please use `read_f32_into` instead")]
#[deprecated(since = "1.2.0", note = "please use `read_f32_into` instead")]
fn read_f32_into_unchecked<T: ByteOrder>(
&mut self,
dst: &mut [f32],
Expand Down Expand Up @@ -991,10 +988,7 @@ pub trait ReadBytesExt: io::Read {
/// assert_eq!([f64::consts::PI, 1.0], dst);
/// ```
#[inline]
fn read_f64_into<T: ByteOrder>(
&mut self,
dst: &mut [f64],
) -> Result<()> {
fn read_f64_into<T: ByteOrder>(&mut self, dst: &mut [f64]) -> Result<()> {
{
let buf = unsafe { slice_to_u8_mut(dst) };
try!(self.read_exact(buf));
Expand Down Expand Up @@ -1045,7 +1039,7 @@ pub trait ReadBytesExt: io::Read {
/// assert_eq!([f64::consts::PI, 1.0], dst);
/// ```
#[inline]
#[deprecated(since="1.2.0", note="please use `read_f64_into` instead")]
#[deprecated(since = "1.2.0", note = "please use `read_f64_into` instead")]
fn read_f64_into_unchecked<T: ByteOrder>(
&mut self,
dst: &mut [f64],
Expand Down
Loading

0 comments on commit f86396e

Please sign in to comment.