]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Optimize resolve_xref to avoid O(n^2) iteration
authorPetr Špaček <pspacek@isc.org>
Mon, 4 Jul 2022 09:01:17 +0000 (11:01 +0200)
committerPetr Špaček <pspacek@isc.org>
Mon, 4 Jul 2022 10:39:43 +0000 (12:39 +0200)
Formerly resolve_xref() in Sphinx extension called get_objects() from
Sphinx API which subsequently iterated the whole list of objects,
causing single iteration per single reference, which is essentially.
O(n^2). Avoid using get_objects() and access internal dictionary
directly intead.

The docs build time was still dominated by other factors but speedup is
about 10 % on my machine.

doc/arm/_ext/iscconf.py

index 4380a8c4c1a8cda6c3ab457fd1acb99b9fcaf8e7..53eb2f946ae888f10215c30ff550b6f5b164cc63 100644 (file)
@@ -305,19 +305,18 @@ def domain_factory(domainname, domainlabel, todolist, grammar):
             Sphinx API:
             Resolve the pending_xref *node* with the given typ and target.
             """
-            match = [
-                (docname, anchor)
-                for name, sig, typ, docname, anchor, _prio in self.get_objects()
-                if sig == target
-            ]
-
-            if len(match) == 0:
+            try:
+                obj = self.data["statements"][self.get_statement_name(target)]
+            except KeyError:
                 return None
-            todocname = match[0][0]
-            targ = match[0][1]
 
             refnode = make_refnode(
-                builder, fromdocname, todocname, targ, contnode, targ
+                builder,
+                fromdocname,
+                obj["docname"],
+                obj["anchor"],
+                contnode,
+                obj["anchor"],
             )
             return refnode