Skip to content

Commit a27752c

Browse files
committed
Put rayon back in.
1 parent 7484d4d commit a27752c

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ dirs = "*"
1515
serde = "*"
1616
docopt = "*"
1717
cached = "*"
18+
rayon = "*"

src/main.rs

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
use lazy_static::lazy_static;
12
use regex::Regex;
2-
use std::path::{Path, PathBuf};
3+
use std::fs::File;
34
use std::io::prelude::*;
45
use std::io::BufReader;
5-
use std::fs::File;
6-
use lazy_static::lazy_static;
6+
use std::path::{Path, PathBuf};
77
// TODO use clap
8+
use cached::proc_macro::cached;
89
use docopt::Docopt;
10+
use reqwest::blocking::Client;
911
use serde::Deserialize;
1012
use std::ffi::CString;
11-
use cached::proc_macro::cached;
12-
use reqwest::blocking::Client;
1313

1414
/// For libxml2 FFI.
1515
use libc::{c_char, c_int, c_uint, FILE};
@@ -32,7 +32,10 @@ extern "C" {
3232
pub fn xmlInitGlobals();
3333

3434
// xmlschemas
35-
pub fn xmlSchemaNewMemParserCtxt(buffer: *const c_char, size: c_int) -> *mut XmlSchemaParserCtxt;
35+
pub fn xmlSchemaNewMemParserCtxt(
36+
buffer: *const c_char,
37+
size: c_int,
38+
) -> *mut XmlSchemaParserCtxt;
3639
//pub fn xmlSchemaSetParserErrors();
3740
pub fn xmlSchemaParse(ctxt: *const XmlSchemaParserCtxt) -> *mut XmlSchema;
3841
pub fn xmlSchemaFreeParserCtxt(ctxt: *mut XmlSchemaParserCtxt);
@@ -101,8 +104,8 @@ fn get_schema(url: String) -> XmlSchemaPtr {
101104
let response = CLIENT.get(url.as_str()).send().unwrap().bytes().unwrap();
102105

103106
unsafe {
104-
let schema_parser_ctxt = xmlSchemaNewMemParserCtxt(response.as_ptr() as *const c_char,
105-
response.len() as i32);
107+
let schema_parser_ctxt =
108+
xmlSchemaNewMemParserCtxt(response.as_ptr() as *const c_char, response.len() as i32);
106109

107110
// Use default callbacks rather than overriding.
108111
//xmlSchemaSetParserErrors();
@@ -137,9 +140,7 @@ fn validate(path_buf: PathBuf) {
137140
// Note: the message is output after the validation messages.
138141
eprintln!("{path_str} fails to validate");
139142
} else {
140-
eprintln!(
141-
"{path_str} validation generated an internal error"
142-
);
143+
eprintln!("{path_str} validation generated an internal error");
143144
}
144145

145146
xmlSchemaFreeValidCtxt(schema_valid_ctxt);
@@ -158,14 +159,18 @@ fn main() {
158159
}
159160

160161
// No real point in using WalkParallel.
161-
for result in ignore::Walk::new(&args.arg_dir) {
162-
if let Ok(entry) = result {
163-
let path = entry.path().to_owned();
164-
if let Some(extension) = path.extension() {
165-
if extension.to_str().unwrap() == extension_str {
166-
validate(path);
162+
rayon::scope(|scope| {
163+
for result in ignore::Walk::new(&args.arg_dir) {
164+
scope.spawn(move |_| {
165+
if let Ok(entry) = result {
166+
let path = entry.path().to_owned();
167+
if let Some(extension) = path.extension() {
168+
if extension.to_str().unwrap() == extension_str {
169+
validate(path);
170+
}
171+
}
167172
}
168-
}
173+
});
169174
}
170-
}
175+
});
171176
}

0 commit comments

Comments
 (0)