diff --git a/scaladoc/src/dotty/tools/scaladoc/api.scala b/scaladoc/src/dotty/tools/scaladoc/api.scala index 5af55f76a211..159db2ecaf7b 100644 --- a/scaladoc/src/dotty/tools/scaladoc/api.scala +++ b/scaladoc/src/dotty/tools/scaladoc/api.scala @@ -145,10 +145,10 @@ case class LinkToType(signature: Signature, dri: DRI, kind: Kind) case class HierarchyGraph(edges: Seq[(LinkToType, LinkToType)], sealedNodes: Set[LinkToType] = Set.empty): def vertecies: Seq[LinkToType] = edges.flatten((a, b) => Seq(a, b)).distinct def verteciesWithId: Map[LinkToType, Int] = vertecies.zipWithIndex.toMap - def +(edge: (LinkToType, LinkToType)): HierarchyGraph = HierarchyGraph((edges :+ edge).distinct) - def ++(edges: Seq[(LinkToType, LinkToType)]): HierarchyGraph = edges.foldLeft(this) { - case (acc, edge) => acc + edge - } + def +(edge: (LinkToType, LinkToType)): HierarchyGraph = this ++ Seq(edge) + def ++(edges: Seq[(LinkToType, LinkToType)]): HierarchyGraph = + this.copy(edges = this.edges.view.concat(edges).distinct.toSeq) + object HierarchyGraph: def empty = HierarchyGraph(Seq.empty) def withEdges(edges: Seq[(LinkToType, LinkToType)]) = HierarchyGraph.empty ++ edges diff --git a/scaladoc/src/dotty/tools/scaladoc/transformers/InheritanceInformationTransformer.scala b/scaladoc/src/dotty/tools/scaladoc/transformers/InheritanceInformationTransformer.scala index 02e224f10cf0..b027aff83f6d 100644 --- a/scaladoc/src/dotty/tools/scaladoc/transformers/InheritanceInformationTransformer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/transformers/InheritanceInformationTransformer.scala @@ -3,16 +3,16 @@ package transformers class InheritanceInformationTransformer(using DocContext) extends (Module => Module): override def apply(original: Module): Module = - val subtypes = getSupertypes(original.rootPackage).groupMap(_(0))(_(1)) + val subtypes = getSupertypes(original.rootPackage).groupMap(_(0))(_(1)).view.mapValues(_.distinct).toMap original.updateMembers { m => val edges = getEdges(m.asLink.copy(kind = bareClasslikeKind(m.kind)), subtypes) val st: Seq[LinkToType] = edges.map(_._1).distinct - m.withKnownChildren(st).withNewGraphEdges(edges) + m.withKnownChildren(st).withNewGraphEdges(edges.toSeq) } private def getEdges(ltt: LinkToType, subtypes: Map[DRI, Seq[LinkToType]]): Seq[(LinkToType, LinkToType)] = - val st: Seq[LinkToType] = subtypes.getOrElse(ltt.dri, Nil) - st.flatMap(s => Seq(s -> ltt) ++ getEdges(s, subtypes)) + val st: Seq[LinkToType] = subtypes.getOrElse(ltt.dri, Vector.empty) + st.flatMap(s => Vector(s -> ltt) ++ getEdges(s, subtypes)) private def bareClasslikeKind(kind: Kind): Kind = kind match case _: Kind.Trait => Kind.Trait(Nil, Nil)