make any_pat! and u64_from_be_bytes_bench_impl! macros hygienic

This commit is contained in:
John Clements 2014-07-03 13:10:54 -07:00
parent 0ba15c99f3
commit 3e99309bfc
2 changed files with 13 additions and 12 deletions

View file

@ -796,9 +796,9 @@ fn extract_vec_elems<'a>(
// matches should fit that sort of pattern or NONE (however, some of the
// matches may be wildcards like _ or identifiers).
macro_rules! any_pat (
($m:expr, $pattern:pat) => (
($m:expr, $col:expr, $pattern:pat) => (
($m).iter().any(|br| {
match br.pats.get(col).node {
match br.pats.get($col).node {
$pattern => true,
_ => false
}
@ -807,11 +807,11 @@ macro_rules! any_pat (
)
fn any_uniq_pat(m: &[Match], col: uint) -> bool {
any_pat!(m, ast::PatBox(_))
any_pat!(m, col, ast::PatBox(_))
}
fn any_region_pat(m: &[Match], col: uint) -> bool {
any_pat!(m, ast::PatRegion(_))
any_pat!(m, col, ast::PatRegion(_))
}
fn any_irrefutable_adt_pat(bcx: &Block, m: &[Match], col: uint) -> bool {

View file

@ -508,14 +508,15 @@ mod bench {
use prelude::*;
use self::test::Bencher;
// why is this a macro? wouldn't an inlined function work just as well?
macro_rules! u64_from_be_bytes_bench_impl(
($size:expr, $stride:expr, $start_index:expr) =>
($b:expr, $size:expr, $stride:expr, $start_index:expr) =>
({
use super::u64_from_be_bytes;
let data = Vec::from_fn($stride*100+$start_index, |i| i as u8);
let mut sum = 0u64;
b.iter(|| {
$b.iter(|| {
let mut i = $start_index;
while i < data.len() {
sum += u64_from_be_bytes(data.as_slice(), i, $size);
@ -527,31 +528,31 @@ mod bench {
#[bench]
fn u64_from_be_bytes_4_aligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(4, 4, 0);
u64_from_be_bytes_bench_impl!(b, 4, 4, 0);
}
#[bench]
fn u64_from_be_bytes_4_unaligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(4, 4, 1);
u64_from_be_bytes_bench_impl!(b, 4, 4, 1);
}
#[bench]
fn u64_from_be_bytes_7_aligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(7, 8, 0);
u64_from_be_bytes_bench_impl!(b, 7, 8, 0);
}
#[bench]
fn u64_from_be_bytes_7_unaligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(7, 8, 1);
u64_from_be_bytes_bench_impl!(b, 7, 8, 1);
}
#[bench]
fn u64_from_be_bytes_8_aligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(8, 8, 0);
u64_from_be_bytes_bench_impl!(b, 8, 8, 0);
}
#[bench]
fn u64_from_be_bytes_8_unaligned(b: &mut Bencher) {
u64_from_be_bytes_bench_impl!(8, 8, 1);
u64_from_be_bytes_bench_impl!(b, 8, 8, 1);
}
}