cache the example url to solve performance problem

This commit is contained in:
Eh2406 2018-08-21 16:21:53 -04:00
parent 56a222cd30
commit 17618869e0
2 changed files with 9 additions and 6 deletions

View file

@ -9,6 +9,8 @@ extern crate flate2;
extern crate git2;
extern crate glob;
extern crate hex;
#[macro_use]
extern crate lazy_static;
extern crate libc;
#[macro_use]
extern crate proptest;

View file

@ -62,10 +62,13 @@ trait ToDep {
fn to_dep(self) -> Dependency;
}
lazy_static! {
static ref EXAMPLE_DOT_COM: ::url::Url = "http://example.com".to_url().unwrap();
}
impl ToDep for &'static str {
fn to_dep(self) -> Dependency {
let url = "http://example.com".to_url().unwrap();
let source_id = SourceId::for_registry(&url).unwrap();
let source_id = SourceId::for_registry(&EXAMPLE_DOT_COM).unwrap();
Dependency::parse_no_deprecated(self, Some("1.0.0"), &source_id).unwrap()
}
}
@ -117,8 +120,7 @@ macro_rules! pkg {
}
fn registry_loc() -> SourceId {
let remote = "http://example.com".to_url().unwrap();
SourceId::for_registry(&remote).unwrap()
SourceId::for_registry(&EXAMPLE_DOT_COM).unwrap()
}
fn pkg(name: &str) -> Summary {
@ -161,8 +163,7 @@ fn dep(name: &str) -> Dependency {
dep_req(name, "1.0.0")
}
fn dep_req(name: &str, req: &str) -> Dependency {
let url = "http://example.com".to_url().unwrap();
let source_id = SourceId::for_registry(&url).unwrap();
let source_id = SourceId::for_registry(&EXAMPLE_DOT_COM).unwrap();
Dependency::parse_no_deprecated(name, Some(req), &source_id).unwrap()
}