forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#136828 - yotamofek:pr/rustdoc/more-laziness, …
…r=<try> Do more lazy-formatting in `librustdoc` 🦥 Modify some formatting to be lazy, i.e. to not allocate interim strings that are later formatted into different strings. Commits are small and stand on their own, and should mostly compile separately. (The first one doesn't compile due to `dead_code` because all it does is introduce a helper used in later commits) Really excited about this one, local perf results are really good. I'd love a perf run to see how this looks on CI. This is the comparison of `instructions:u` count between master and this PR, on my computer: # Summary | | Range | Mean | Count | |:---:|:---:|:---:|:---:| | Regressions | - | 0.00% | 0 | | Improvements | -8.03%, -0.40% | -2.93% | 5 | | All | -8.03%, -0.40% | -2.93% | 5 | # Primary benchmarks | Benchmark | Profile | Scenario | % Change | Significance Factor | |:---:|:---:|:---:|:---:|:---:| | typenum-1.17.0 | doc | full | -8.03% | 40.16x | | nalgebra-0.33.0 | doc | full | -4.19% | 20.97x | | stm32f4-0.14.0 | doc | full | -1.35% | 6.73x | | libc-0.2.124 | doc | full | -0.67% | 3.33x | | cranelift-codegen-0.82.1 | doc | full | -0.40% | 1.99x |
- Loading branch information
Showing
9 changed files
with
162 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::fmt::{self, Display}; | ||
|
||
pub(crate) trait MaybeDisplay { | ||
/// For a given `Option<T: Display>`, returns a `Display` implementation that will display `t` if `Some(t)`, or nothing if `None`. | ||
fn maybe_display(self) -> impl Display; | ||
} | ||
|
||
impl<T: Display> MaybeDisplay for Option<T> { | ||
fn maybe_display(self) -> impl Display { | ||
fmt::from_fn(move |f| { | ||
if let Some(t) = self.as_ref() { | ||
t.fmt(f)?; | ||
} | ||
Ok(()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Various utilities for working with [`fmt::Display`](std::fmt::Display) implementations. | ||
mod joined; | ||
mod maybe; | ||
|
||
pub(crate) use self::joined::Joined; | ||
pub(crate) use self::maybe::MaybeDisplay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.