Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

docs: automarkup: do not look up symbols twice

The automarkup code tries to look up symbols once as a function, and once
as a macro. The Sphinx C domain code, though, totally ignores that
distinction and will return the same results either way. So just look
things up once and be done with it; the resulting output does not change,
but htmldocs build time drops by about 5%.

Tested-by: Akira Yokosawa <akiyks@gmail.com>
Link: https://lore.kernel.org/r/20220630163630.714673-3-corbet@lwn.net
Signed-off-by: Jonathan Corbet <corbet@lwn.net>

+25 -30
+25 -30
Documentation/sphinx/automarkup.py
··· 125 125 # do them again. 126 126 # 127 127 failed_lookups = { } 128 - def failure_seen(target, reftype): 129 - return (target + '::' + reftype) in failed_lookups 130 - def note_failure(target, reftype): 131 - failed_lookups[target + '::' + reftype] = True 128 + def failure_seen(target): 129 + return (target) in failed_lookups 130 + def note_failure(target): 131 + failed_lookups[target] = True 132 132 133 133 # 134 134 # In sphinx3 we can cross-reference to C macro and function, each one with its 135 135 # own C role, but both match the same regex, so we try both. 136 136 # 137 137 def markup_func_ref_sphinx3(docname, app, match): 138 - class_str = ['c-func', 'c-macro'] 139 - reftype_str = ['function', 'macro'] 140 - 141 138 cdom = app.env.domains['c'] 142 139 # 143 140 # Go through the dance of getting an xref out of the C domain ··· 150 153 151 154 if base_target not in Skipnames: 152 155 for target in possible_targets: 153 - if target not in Skipfuncs: 154 - for class_s, reftype_s in zip(class_str, reftype_str): 155 - if failure_seen(target, reftype_s): 156 - continue 157 - lit_text = nodes.literal(classes=['xref', 'c', class_s]) 158 - lit_text += target_text 159 - pxref = addnodes.pending_xref('', refdomain = 'c', 160 - reftype = reftype_s, 161 - reftarget = target, modname = None, 162 - classname = None) 163 - # 164 - # XXX The Latex builder will throw NoUri exceptions here, 165 - # work around that by ignoring them. 166 - # 167 - try: 168 - xref = cdom.resolve_xref(app.env, docname, app.builder, 169 - reftype_s, target, pxref, 170 - lit_text) 171 - except NoUri: 172 - xref = None 156 + if (target not in Skipfuncs) and not failure_seen(target): 157 + lit_text = nodes.literal(classes=['xref', 'c', 'c-func']) 158 + lit_text += target_text 159 + pxref = addnodes.pending_xref('', refdomain = 'c', 160 + reftype = 'function', 161 + reftarget = target, 162 + modname = None, 163 + classname = None) 164 + # 165 + # XXX The Latex builder will throw NoUri exceptions here, 166 + # work around that by ignoring them. 167 + # 168 + try: 169 + xref = cdom.resolve_xref(app.env, docname, app.builder, 170 + 'function', target, pxref, 171 + lit_text) 172 + except NoUri: 173 + xref = None 173 174 174 - if xref: 175 - return xref 176 - note_failure(target, reftype_s) 175 + if xref: 176 + return xref 177 + note_failure(target) 177 178 178 179 return target_text 179 180