diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2023-03-20 19:36:36 +0400 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2023-03-20 19:43:00 +0400 |
| commit | 4d55affc12da448e4a99bf538ccfd66e7ffae5cb (patch) | |
| tree | 4ac2dd4d5de94c67a1c29f1627521afee9d3d3b0 | |
| parent | 13b7aa4d7faafbed78d195c27f6868f6bd90c2f8 (diff) | |
| download | rust-4d55affc12da448e4a99bf538ccfd66e7ffae5cb.tar.gz rust-4d55affc12da448e4a99bf538ccfd66e7ffae5cb.zip | |
rustdoc: Optimize impl sorting during rendering
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 7eb9c0b7cf5..579b5a9c723 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -880,8 +880,8 @@ fn item_trait(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, t: &clean: let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) = local.iter().partition(|i| i.inner_impl().kind.is_auto()); - synthetic.sort_by(|a, b| compare_impl(a, b, cx)); - concrete.sort_by(|a, b| compare_impl(a, b, cx)); + synthetic.sort_by_cached_key(|i| ImplString::new(i, cx)); + concrete.sort_by_cached_key(|i| ImplString::new(i, cx)); if !foreign.is_empty() { write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", ""); @@ -1597,12 +1597,25 @@ where w.write_str("</code></pre>"); } -fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl, cx: &Context<'_>) -> Ordering { - let lhss = format!("{}", lhs.inner_impl().print(false, cx)); - let rhss = format!("{}", rhs.inner_impl().print(false, cx)); +#[derive(PartialEq, Eq)] +struct ImplString(String); - // lhs and rhs are formatted as HTML, which may be unnecessary - compare_names(&lhss, &rhss) +impl ImplString { + fn new(i: &Impl, cx: &Context<'_>) -> ImplString { + ImplString(format!("{}", i.inner_impl().print(false, cx))) + } +} + +impl PartialOrd for ImplString { + fn partial_cmp(&self, other: &Self) -> Option<Ordering> { + Some(Ord::cmp(self, other)) + } +} + +impl Ord for ImplString { + fn cmp(&self, other: &Self) -> Ordering { + compare_names(&self.0, &other.0) + } } fn render_implementor( |
