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.
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