about summary refs log tree commit diff
path: root/src/librustdoc/html
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-09-13 16:51:31 +0530
committerGitHub <noreply@github.com>2022-09-13 16:51:31 +0530
commitd5b86d5ee912407aef6af3a152a94bde70bacb7a (patch)
tree9effa6a3c60a5ab146fd1d50d0e7e6cb1b01f7b0 /src/librustdoc/html
parentdb75d7e14b6c5157e12fea4a1158e9dd58e92c36 (diff)
parent66211d83f9ad82770f2f81d37aae1544365a9a32 (diff)
Rollup merge of #101690 - kadiwa4:avoid_iterator_last, r=oli-obk
Avoid `Iterator::last`

Adapters like `Filter` and `Map` use the default implementation of `Iterator::last` which is not short-circuiting (and so does `core::str::Split`). The predicate function will be run for every single item of the underlying iterator. I hope that removing those calls to `last` results in slight performance improvements.
Diffstat (limited to 'src/librustdoc/html')
-rw-r--r--src/librustdoc/html/format.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index be10a5c101f..ec6b8c2469c 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -587,7 +587,7 @@ fn generate_macro_def_id_path(
             }
         })
         .collect();
-    let relative = fqp.iter().map(|elem| elem.to_string());
+    let mut relative = fqp.iter().map(|elem| elem.to_string());
     let cstore = CStore::from_tcx(tcx);
     // We need this to prevent a `panic` when this function is used from intra doc links...
     if !cstore.has_crate_data(def_id.krate) {
@@ -607,7 +607,7 @@ fn generate_macro_def_id_path(
     let mut path = if is_macro_2 {
         once(crate_name.clone()).chain(relative).collect()
     } else {
-        vec![crate_name.clone(), relative.last().unwrap()]
+        vec![crate_name.clone(), relative.next_back().unwrap()]
     };
     if path.len() < 2 {
         // The minimum we can have is the crate name followed by the macro name. If shorter, then