]> git.lizzy.rs Git - rust.git/commitdiff
remove O(n^2) to O(n) behavior
authorEsteban Küber <esteban@kuber.com.ar>
Mon, 19 Dec 2016 21:30:42 +0000 (13:30 -0800)
committerEsteban Küber <esteban@kuber.com.ar>
Mon, 19 Dec 2016 21:30:42 +0000 (13:30 -0800)
src/librustdoc/html/render.rs

index c7a25814553777f785d664492b2ef504d8e4a92b..846c0721ccbd3cd6c0efe242818c62d6b6cbdee9 100644 (file)
@@ -2110,24 +2110,27 @@ fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean::
         <h2 id='implementors'>Implementors</h2>
         <ul class='item-list' id='implementors-list'>
     ")?;
+    let mut implementor_count: FxHashMap<String, usize> = FxHashMap();
+    for (_, implementors) in cache.implementors.iter() {
+        for implementor in implementors {
+            if let clean::Type::ResolvedPath {ref path, ..} = implementor.impl_.for_ {
+                *implementor_count.entry(path.last_name()).or_insert(0) += 1;
+            }
+        }
+    }
     if let Some(implementors) = cache.implementors.get(&it.def_id) {
-        for k in implementors.iter() {
+        for implementor in implementors.iter() {
             write!(w, "<li><code>")?;
             // If there's already another implementor that has the same abbridged name, use the
             // full path, for example in `std::iter::ExactSizeIterator`
-            let mut dissambiguate = false;
-            for l in implementors.iter() {
-                match (k.impl_.for_.clone(), l.impl_.for_.clone()) {
-                    (clean::Type::ResolvedPath {path: path_a, ..},
-                     clean::Type::ResolvedPath {path: path_b, ..}) => {
-                        if k.def_id != l.def_id && path_a.last_name() == path_b.last_name() {
-                            dissambiguate = true;
-                        }
-                    }
-                    _ => (),
-                }
-            }
-            fmt_impl_for_trait_page(&k.impl_, w, dissambiguate)?;
+            let dissambiguate = if let clean::Type::ResolvedPath {
+                ref path, ..
+            } = implementor.impl_.for_ {
+                *implementor_count.get(&path.last_name()).unwrap_or(&0) > 1
+            } else {
+                false
+            };
+            fmt_impl_for_trait_page(&implementor.impl_, w, dissambiguate)?;
             writeln!(w, "</code></li>")?;
         }
     }