Skip to content

Commit 8e05bb5

Browse files
committed
Auto merge of rust-lang#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.
2 parents 7ae5508 + 141c542 commit 8e05bb5

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/librustdoc/html/format.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ crate fn print_generic_bounds<'a, 'tcx: 'a>(
141141
display_fn(move |f| {
142142
let mut bounds_dup = FxHashSet::default();
143143

144-
for (i, bound) in
145-
bounds.iter().filter(|b| bounds_dup.insert(b.print(cx).to_string())).enumerate()
146-
{
144+
for (i, bound) in bounds.iter().filter(|b| bounds_dup.insert(b.clone())).enumerate() {
147145
if i > 0 {
148146
f.write_str(" + ")?;
149147
}

0 commit comments

Comments
 (0)