about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-12-29 02:49:34 +0000
committerbors <bors@rust-lang.org>2021-12-29 02:49:34 +0000
commit8e05bb527c5f00549ea6bc21352638200bceb1a5 (patch)
tree17a3d48398a2acef9341636d5617a1d0d94573c7
parent7ae550842635dce84811198446fe87e830de500b (diff)
parent141c542052c1adec045136212a42f241ba3fb9a9 (diff)
downloadrust-8e05bb527c5f00549ea6bc21352638200bceb1a5.tar.gz
rust-8e05bb527c5f00549ea6bc21352638200bceb1a5.zip
Auto merge of #92283 - vacuus:print-generic-bounds, r=camelid,GuillaumeGomez
rustdoc: Remove `String` allocation in iteration in `print_generic_bounds`

(I realized only after making the commit that maybe I shouldn't refer to iteration as looping, but it's close enough)

The string representation of a `clean::GenericBound` instance (evaluated [here](https://github.com/rust-lang/rust/blob/master/src/librustdoc/html/format.rs#L397)) is deterministic for a given `self` (the instance), `cx` and `f`, and since `cx` and `f` are constant (as far as I can tell) for a given invocation of `print_generic_bounds`, `self` is the determining factor. Therefore, using the data in `self` shouldn't differ in effect from using its string representation.

Given the totality of the function calls needed to evaluate the string representation as well as the actual allocation, at the very least, this shouldn't negatively affect performance.
-rw-r--r--src/librustdoc/html/format.rs4
1 files changed, 1 insertions, 3 deletions
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index d446626cb06..e4c612aaab9 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -141,9 +141,7 @@ crate fn print_generic_bounds<'a, 'tcx: 'a>(
     display_fn(move |f| {
         let mut bounds_dup = FxHashSet::default();
 
-        for (i, bound) in
-            bounds.iter().filter(|b| bounds_dup.insert(b.print(cx).to_string())).enumerate()
-        {
+        for (i, bound) in bounds.iter().filter(|b| bounds_dup.insert(b.clone())).enumerate() {
             if i > 0 {
                 f.write_str(" + ")?;
             }