From 10606c3caf42124bf5b8069647badc0cfcc31a89 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sun, 31 Oct 2021 21:07:32 -0700 Subject: [PATCH] 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()` --- src/librustdoc/html/sources.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 30ec592ba23d..c8e93374e63c 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -44,7 +44,7 @@ struct LocalSourcesCollector<'a, 'tcx> { } fn is_real_and_local(span: clean::Span, sess: &Session) -> bool { - span.filename(sess).is_real() && span.cnum(sess) == LOCAL_CRATE + span.cnum(sess) == LOCAL_CRATE && span.filename(sess).is_real() } impl LocalSourcesCollector<'_, '_> { @@ -56,12 +56,13 @@ impl LocalSourcesCollector<'_, '_> { return; } let filename = span.filename(sess); - let p = match filename { - FileName::Real(ref file) => match file.local_path() { - Some(p) => p.to_path_buf(), - _ => return, - }, - _ => return, + let p = if let FileName::Real(file) = filename { + match file.into_local_path() { + Some(p) => p, + None => return, + } + } else { + return; }; if self.local_sources.contains_key(&*p) { // We've already emitted this source