Skip to content

Commit 0e96af4

Browse files
committed
style: start using rustfmt
1 parent 341f207 commit 0e96af4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+36651
-13694
lines changed

bench/build.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,18 @@ fn main() {
6262

6363
if env::var("CARGO_FEATURE_RE_DPHOBOS_DMD").is_ok() {
6464
process::Command::new("dmd")
65-
.arg("--version")
66-
.stdout(process::Stdio::null())
67-
.stderr(process::Stdio::null())
68-
.spawn()
69-
.unwrap();
65+
.arg("--version")
66+
.stdout(process::Stdio::null())
67+
.stderr(process::Stdio::null())
68+
.spawn()
69+
.unwrap();
7070

7171
let out_dir = env::var("OUT_DIR").unwrap();
7272
let out_file = &format!("-of={}/libdphobos-dmd.a", out_dir);
73-
let is_compile_time = env::var("CARGO_FEATURE_RE_DPHOBOS_DMD_CT").is_ok();
74-
let extra_args = if is_compile_time { vec!["-version=CtRegex"] } else { vec![] };
73+
let is_compile_time =
74+
env::var("CARGO_FEATURE_RE_DPHOBOS_DMD_CT").is_ok();
75+
let extra_args =
76+
if is_compile_time { vec!["-version=CtRegex"] } else { vec![] };
7577

7678
let res = process::Command::new("dmd")
7779
.arg("-w")
@@ -99,17 +101,19 @@ fn main() {
99101

100102
if env::var("CARGO_FEATURE_RE_DPHOBOS_LDC").is_ok() {
101103
process::Command::new("ldc")
102-
.arg("--version")
103-
.stdout(process::Stdio::null())
104-
.stderr(process::Stdio::null())
105-
.spawn()
106-
.unwrap();
104+
.arg("--version")
105+
.stdout(process::Stdio::null())
106+
.stderr(process::Stdio::null())
107+
.spawn()
108+
.unwrap();
107109

108110
let out_dir = env::var("OUT_DIR").unwrap();
109111
let out_file = &format!("-of={}/libdphobos-ldc.a", out_dir);
110112

111-
let is_compile_time = env::var("CARGO_FEATURE_RE_DPHOBOS_LDC_CT").is_ok();
112-
let extra_args = if is_compile_time { vec!["-d-version=CtRegex"] } else { vec![] };
113+
let is_compile_time =
114+
env::var("CARGO_FEATURE_RE_DPHOBOS_LDC_CT").is_ok();
115+
let extra_args =
116+
if is_compile_time { vec!["-d-version=CtRegex"] } else { vec![] };
113117

114118
let res = process::Command::new("ldc")
115119
.arg("-w")

bench/src/bench.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ cfg_if! {
6060
// defined below. Effectively, it allows us to use the same tests for both
6161
// native and dynamic regexes.
6262
macro_rules! regex {
63-
($re:expr) => { ::Regex::new(&$re.to_owned()).unwrap() }
63+
($re:expr) => {
64+
::Regex::new(&$re.to_owned()).unwrap()
65+
};
6466
}
6567

6668
cfg_if! {
@@ -119,7 +121,7 @@ cfg_if! {
119121
macro_rules! bench_match {
120122
($name:ident, $pattern:expr, $haystack:expr) => {
121123
bench_is_match!($name, true, regex!($pattern), $haystack);
122-
}
124+
};
123125
}
124126

125127
// USAGE: bench_not_match!(name, pattern, haystack)
@@ -136,7 +138,7 @@ macro_rules! bench_match {
136138
macro_rules! bench_not_match {
137139
($name:ident, $pattern:expr, $haystack:expr) => {
138140
bench_is_match!($name, false, regex!($pattern), $haystack);
139-
}
141+
};
140142
}
141143

142144
// USAGE: bench_is_match!(name, is_match, regex, haystack)
@@ -182,7 +184,7 @@ macro_rules! bench_is_match {
182184
}
183185
});
184186
}
185-
}
187+
};
186188
}
187189

188190
// USAGE: bench_find!(name, pattern, count, haystack)
@@ -214,7 +216,7 @@ macro_rules! bench_find {
214216
assert_eq!($count, count)
215217
});
216218
}
217-
}
219+
};
218220
}
219221

220222
// USAGE: bench_captures!(name, pattern, groups, haystack);
@@ -229,7 +231,6 @@ macro_rules! bench_find {
229231
// the capture groups in question.
230232
macro_rules! bench_captures {
231233
($name:ident, $pattern:expr, $count:expr, $haystack:expr) => {
232-
233234
#[cfg(feature = "re-rust")]
234235
#[bench]
235236
fn $name(b: &mut Bencher) {
@@ -242,14 +243,12 @@ macro_rules! bench_captures {
242243
let re = RE.lock().unwrap();
243244
let text = TEXT.lock().unwrap();
244245
b.bytes = text.len() as u64;
245-
b.iter(|| {
246-
match re.captures(&text) {
247-
None => assert!(false, "no captures"),
248-
Some(caps) => assert_eq!($count + 1, caps.len()),
249-
}
246+
b.iter(|| match re.captures(&text) {
247+
None => assert!(false, "no captures"),
248+
Some(caps) => assert_eq!($count + 1, caps.len()),
250249
});
251250
}
252-
}
251+
};
253252
}
254253

255254
// USAGE: bench_is_match_set!(name, is_match, regex, haystack)
@@ -275,9 +274,9 @@ macro_rules! bench_is_match_set {
275274
}
276275
});
277276
}
278-
}
277+
};
279278
}
280-
279+
281280
// USAGE: bench_matches_set!(name, is_match, regex, haystack)
282281
macro_rules! bench_matches_set {
283282
($name:ident, $is_match:expr, $re:expr, $haystack:expr) => {
@@ -301,7 +300,7 @@ macro_rules! bench_matches_set {
301300
}
302301
});
303302
}
304-
}
303+
};
305304
}
306305

307306
cfg_if! {

bench/src/ffi/d_phobos.rs

+11-24
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,17 @@ impl Regex {
3131
}
3232

3333
pub fn is_match(&self, text: &str) -> bool {
34-
unsafe {
35-
d_phobos_regex_is_match(self.re, text.into())
36-
}
34+
unsafe { d_phobos_regex_is_match(self.re, text.into()) }
3735
}
3836

3937
pub fn find_iter<'r, 't>(&'r self, text: &'t str) -> FindMatches<'r, 't> {
40-
FindMatches {
41-
re: self,
42-
text: text,
43-
last_end: 0,
44-
last_match: None,
45-
}
38+
FindMatches { re: self, text: text, last_end: 0, last_match: None }
4639
}
4740

4841
fn find_at(&self, text: &str, start: usize) -> Option<(usize, usize)> {
4942
let (mut s, mut e): (usize, usize) = (0, 0);
5043
let matched = unsafe {
51-
d_phobos_regex_find_at(
52-
self.re,
53-
text.into(),
54-
start,
55-
&mut s,
56-
&mut e,
57-
)
44+
d_phobos_regex_find_at(self.re, text.into(), start, &mut s, &mut e)
5845
};
5946
if matched {
6047
Some((s, e))
@@ -99,17 +86,17 @@ impl<'a> From<&'a str> for d_string {
9986
}
10087
}
10188

102-
extern {
89+
extern "C" {
10390
fn rt_init() -> i32;
10491
fn rt_term() -> i32;
10592
fn d_phobos_regex_new(s: d_string) -> *mut d_regex;
10693
fn d_phobos_regex_free(r: *mut d_regex);
10794
fn d_phobos_regex_is_match(r: *mut d_regex, s: d_string) -> bool;
108-
fn d_phobos_regex_find_at(r: *mut d_regex,
109-
s: d_string,
110-
start: usize,
111-
match_start: *mut usize,
112-
match_end: *mut usize)
113-
-> bool;
95+
fn d_phobos_regex_find_at(
96+
r: *mut d_regex,
97+
s: d_string,
98+
start: usize,
99+
match_start: *mut usize,
100+
match_end: *mut usize,
101+
) -> bool;
114102
}
115-

bench/src/ffi/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ pub mod onig;
2020
pub mod pcre1;
2121
#[cfg(feature = "re-pcre2")]
2222
pub mod pcre2;
23-
#[cfg(any(
24-
feature = "re-stdcpp",
25-
feature = "re-boost",
26-
))]
27-
pub mod stdcpp;
2823
#[cfg(feature = "re-re2")]
2924
pub mod re2;
25+
#[cfg(any(feature = "re-stdcpp", feature = "re-boost",))]
26+
pub mod stdcpp;
3027
#[cfg(feature = "re-tcl")]
3128
pub mod tcl;

bench/src/ffi/onig.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ impl Regex {
2121

2222
pub fn is_match(&self, text: &str) -> bool {
2323
// Gah. onig's is_match function is anchored, but find is not.
24-
self.0.search_with_options(
25-
text,
26-
0,
27-
text.len(),
28-
onig::SearchOptions::SEARCH_OPTION_NONE,
29-
None,
30-
).is_some()
24+
self.0
25+
.search_with_options(
26+
text,
27+
0,
28+
text.len(),
29+
onig::SearchOptions::SEARCH_OPTION_NONE,
30+
None,
31+
)
32+
.is_some()
3133
}
3234

3335
pub fn find_iter<'r, 't>(

bench/src/ffi/pcre1.rs

+31-37
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010

1111
#![allow(non_snake_case)]
1212

13-
use std::ffi::{CString, CStr};
13+
use std::ffi::{CStr, CString};
1414
use std::fmt;
1515
use std::ptr;
1616

1717
use libc::{c_char, c_int, c_void};
1818
use libpcre_sys::{
19-
PCRE_UTF8, PCRE_NO_UTF8_CHECK, PCRE_ERROR_NOMATCH,
20-
pcre, pcre_extra,
21-
pcre_compile, pcre_free, pcre_study, pcre_free_study, pcre_exec,
19+
pcre, pcre_compile, pcre_exec, pcre_extra, pcre_free, pcre_free_study,
20+
pcre_study, PCRE_ERROR_NOMATCH, PCRE_NO_UTF8_CHECK, PCRE_UTF8,
2221
};
2322

2423
const PCRE_UCP: c_int = 0x20000000;
@@ -53,32 +52,29 @@ impl Regex {
5352
let pattern = CString::new(pattern.to_owned()).unwrap();
5453
let mut errptr: *const c_char = ptr::null();
5554
let mut erroffset: c_int = 0;
56-
let code = unsafe { pcre_compile(
57-
pattern.as_ptr(),
58-
PCRE_UCP | PCRE_UTF8,
59-
&mut errptr,
60-
&mut erroffset,
61-
ptr::null(),
62-
) };
55+
let code = unsafe {
56+
pcre_compile(
57+
pattern.as_ptr(),
58+
PCRE_UCP | PCRE_UTF8,
59+
&mut errptr,
60+
&mut erroffset,
61+
ptr::null(),
62+
)
63+
};
6364
if code.is_null() {
64-
let msg = unsafe {
65-
CStr::from_ptr(errptr).to_str().unwrap().to_owned()
66-
};
65+
let msg =
66+
unsafe { CStr::from_ptr(errptr).to_str().unwrap().to_owned() };
6767
return Err(Error { msg: msg, offset: erroffset });
6868
}
6969

70-
let extra = unsafe { pcre_study(
71-
code,
72-
PCRE_STUDY_JIT_COMPLETE,
73-
&mut errptr,
74-
) };
70+
let extra =
71+
unsafe { pcre_study(code, PCRE_STUDY_JIT_COMPLETE, &mut errptr) };
7572
if extra.is_null() {
7673
if errptr.is_null() {
7774
panic!("unexpected error. Maybe JIT support isn't enabled?");
7875
}
79-
let msg = unsafe {
80-
CStr::from_ptr(errptr).to_str().unwrap().to_owned()
81-
};
76+
let msg =
77+
unsafe { CStr::from_ptr(errptr).to_str().unwrap().to_owned() };
8278
return Err(Error { msg: msg, offset: 0 });
8379
}
8480
Ok(Regex { code: code, extra: extra })
@@ -89,26 +85,24 @@ impl Regex {
8985
}
9086

9187
pub fn find_iter<'r, 't>(&'r self, text: &'t str) -> FindMatches<'r, 't> {
92-
FindMatches {
93-
re: self,
94-
text: text,
95-
last_match_end: 0,
96-
}
88+
FindMatches { re: self, text: text, last_match_end: 0 }
9789
}
9890

9991
fn find_at(&self, text: &str, start: usize) -> Option<(usize, usize)> {
10092
const OVEC_SIZE: usize = 15 * 3; // hopefully enough for benchmarks?
10193
let mut ovec: [c_int; OVEC_SIZE] = [0; OVEC_SIZE];
102-
let err = unsafe { pcre_exec(
103-
self.code,
104-
self.extra,
105-
text.as_ptr() as *const i8,
106-
text.len() as c_int,
107-
start as c_int,
108-
PCRE_NO_UTF8_CHECK,
109-
ovec.as_mut_ptr(),
110-
OVEC_SIZE as c_int,
111-
) };
94+
let err = unsafe {
95+
pcre_exec(
96+
self.code,
97+
self.extra,
98+
text.as_ptr() as *const i8,
99+
text.len() as c_int,
100+
start as c_int,
101+
PCRE_NO_UTF8_CHECK,
102+
ovec.as_mut_ptr(),
103+
OVEC_SIZE as c_int,
104+
)
105+
};
112106
if err == PCRE_ERROR_NOMATCH {
113107
None
114108
} else if err < 0 {

0 commit comments

Comments
 (0)