Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit c53f644

Browse files
authored
Merge pull request #95 from Xanewok/housekeeping
Perform some housekeeping
2 parents cddf398 + d6a528d commit c53f644

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

src/lib.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
446446
})
447447
}
448448

449-
// e.g., https://github.com/rust-lang/rust/blob/master/src/libcollections/string.rs#L261-L263
449+
// e.g., https://github.com/rust-lang/rust/blob/master/src/liballoc/string.rs#L261-L263
450450
pub fn src_url(&self, span: &Span) -> AResult<String> {
451451
// FIXME would be nice not to do this every time.
452452
let path_prefix = &self.loader.abs_path_prefix();
@@ -535,15 +535,8 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
535535
return None;
536536
}
537537

538-
let path_prefix = match path_prefix {
539-
Some(pp) => pp,
540-
None => return None,
541-
};
542538
let file_path = &def.span.file;
543-
let file_path = match file_path.strip_prefix(&path_prefix) {
544-
Ok(p) => p,
545-
Err(_) => return None,
546-
};
539+
let file_path = file_path.strip_prefix(path_prefix?).ok()?;
547540

548541
Some(format!(
549542
"{}/{}#L{}-L{}",

src/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl CrateReader {
341341
return NULL;
342342
}
343343
// We build an id by looking up the local crate number into a global crate number and using
344-
// that for the high order bits, then use the index for the least significant bits.
344+
// that for the high order bits, then use the index for the least significant bits.
345345

346346
let krate = self.crate_map[id.krate as usize] as u64;
347347

src/raw.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,10 @@ pub fn read_analyis_incremental<L: AnalysisLoader>(
7070
}
7171

7272
match timestamps.get(&path) {
73-
Some(t) => if time > t {
74-
read_crate_data(&path)
75-
.map(|a| result.push(Crate::new(a, *time, Some(path))));
76-
},
77-
// A crate we've never seen before.
78-
None => {
73+
// We have fresher data than what we can read.
74+
Some(t) => if time <= t {},
75+
// We have old data or it's a crate we've never seen before.
76+
_ => {
7977
read_crate_data(&path)
8078
.map(|a| result.push(Crate::new(a, *time, Some(path))));
8179
}
@@ -105,14 +103,21 @@ fn ignore_data(file_name: &str, crate_blacklist: Blacklist) -> bool {
105103
false
106104
}
107105

106+
fn read_file_contents(path: &Path) -> Result<String, ::std::io::Error> {
107+
let mut file = File::open(&path)?;
108+
let mut buf = String::new();
109+
file.read_to_string(&mut buf)?;
110+
Ok(buf)
111+
}
108112

109113
fn read_crate_data(path: &Path) -> Option<Analysis> {
110114
trace!("read_crate_data {:?}", path);
111-
// TODO unwraps
112115
let t = Instant::now();
113-
let mut file = File::open(&path).unwrap();
114-
let mut buf = String::new();
115-
file.read_to_string(&mut buf).unwrap();
116+
117+
let buf = read_file_contents(path).or_else(|err| {
118+
info!("couldn't read file: {}", err);
119+
Err(err)
120+
}).ok()?;
116121
let s = ::rustc_serialize::json::decode(&buf);
117122

118123
let d = t.elapsed();

src/util.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
macro_rules! option_try(
10-
($e:expr) => (match $e { Some(e) => e, None => return None })
11-
);
12-
139
#[cfg(unix)]
1410
pub fn get_resident() -> Option<usize> {
1511
use std::fs::File;
1612
use std::io::Read;
1713

1814
let field = 1;
19-
let mut f = option_try!(File::open("/proc/self/statm").ok());
15+
let mut f = File::open("/proc/self/statm").ok()?;
2016
let mut contents = String::new();
21-
option_try!(f.read_to_string(&mut contents).ok());
22-
let s = option_try!(contents.split_whitespace().nth(field));
23-
let npages = option_try!(s.parse::<usize>().ok());
17+
f.read_to_string(&mut contents).ok()?;
18+
let s = contents.split_whitespace().nth(field)?;
19+
let npages = s.parse::<usize>().ok()?;
2420
Some(npages * 4096)
2521
}
2622

0 commit comments

Comments
 (0)