about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYotam Ofek <yotam.ofek@gmail.com>2025-06-18 09:49:12 +0000
committerYotam Ofek <yotam.ofek@gmail.com>2025-06-19 10:26:13 +0000
commit569aa26e7bf7f3742fbd6ab3ea3e3c5f9b8d8a75 (patch)
tree20c353292dfff04d80f57a20d4b0f9fde6bac820
parent867c1d5ebf15b1c710cf892c032ad5ec047b34b9 (diff)
downloadrust-569aa26e7bf7f3742fbd6ab3ea3e3c5f9b8d8a75.tar.gz
rust-569aa26e7bf7f3742fbd6ab3ea3e3c5f9b8d8a75.zip
avoid intermediately collecting into vectors
-rw-r--r--src/librustdoc/html/render/write_shared.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index 7433c627674..fc8111fffdc 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -733,7 +733,7 @@ impl TraitAliasPart {
                 },
             };
 
-            let implementors = imps
+            let mut implementors = imps
                 .iter()
                 .filter_map(|imp| {
                     // If the trait and implementation are in the same crate, then
@@ -755,12 +755,12 @@ impl TraitAliasPart {
                         })
                     }
                 })
-                .collect::<Vec<_>>();
+                .peekable();
 
             // Only create a js file if we have impls to add to it. If the trait is
             // documented locally though we always create the file to avoid dead
             // links.
-            if implementors.is_empty() && !cache.paths.contains_key(&did) {
+            if implementors.peek().is_none() && !cache.paths.contains_key(&did) {
                 continue;
             }
 
@@ -771,11 +771,7 @@ impl TraitAliasPart {
             path.push(format!("{remote_item_type}.{}.js", remote_path[remote_path.len() - 1]));
 
             let part = OrderedJson::array_sorted(
-                implementors
-                    .iter()
-                    .map(OrderedJson::serialize)
-                    .collect::<Result<Vec<_>, _>>()
-                    .unwrap(),
+                implementors.map(|implementor| OrderedJson::serialize(implementor).unwrap()),
             );
             path_parts.push(path, OrderedJson::array_unsorted([crate_name_json, &part]));
         }