Skip to content

Commit 10606c3

Browse files
committed
rustdoc: Small micro-optimizations and cleanups
* Flip conjuncts of `&&` in rustdoc The `CrateNum` comparison should be very cheap, while `span.filename()` fetches and clones a `FileName`. * Use `into_local_path()` instead of `local_path().clone()`
1 parent 4ee2d03 commit 10606c3

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/librustdoc/html/sources.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct LocalSourcesCollector<'a, 'tcx> {
4444
}
4545

4646
fn is_real_and_local(span: clean::Span, sess: &Session) -> bool {
47-
span.filename(sess).is_real() && span.cnum(sess) == LOCAL_CRATE
47+
span.cnum(sess) == LOCAL_CRATE && span.filename(sess).is_real()
4848
}
4949

5050
impl LocalSourcesCollector<'_, '_> {
@@ -56,12 +56,13 @@ impl LocalSourcesCollector<'_, '_> {
5656
return;
5757
}
5858
let filename = span.filename(sess);
59-
let p = match filename {
60-
FileName::Real(ref file) => match file.local_path() {
61-
Some(p) => p.to_path_buf(),
62-
_ => return,
63-
},
64-
_ => return,
59+
let p = if let FileName::Real(file) = filename {
60+
match file.into_local_path() {
61+
Some(p) => p,
62+
None => return,
63+
}
64+
} else {
65+
return;
6566
};
6667
if self.local_sources.contains_key(&*p) {
6768
// We've already emitted this source

0 commit comments

Comments
 (0)