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>
This commit is contained in:
Родитель
26c82972f2
Коммит
309027b57c
|
@ -125,19 +125,16 @@ def markup_refs(docname, app, node):
|
||||||
# do them again.
|
# do them again.
|
||||||
#
|
#
|
||||||
failed_lookups = { }
|
failed_lookups = { }
|
||||||
def failure_seen(target, reftype):
|
def failure_seen(target):
|
||||||
return (target + '::' + reftype) in failed_lookups
|
return (target) in failed_lookups
|
||||||
def note_failure(target, reftype):
|
def note_failure(target):
|
||||||
failed_lookups[target + '::' + reftype] = True
|
failed_lookups[target] = True
|
||||||
|
|
||||||
#
|
#
|
||||||
# In sphinx3 we can cross-reference to C macro and function, each one with its
|
# In sphinx3 we can cross-reference to C macro and function, each one with its
|
||||||
# own C role, but both match the same regex, so we try both.
|
# own C role, but both match the same regex, so we try both.
|
||||||
#
|
#
|
||||||
def markup_func_ref_sphinx3(docname, app, match):
|
def markup_func_ref_sphinx3(docname, app, match):
|
||||||
class_str = ['c-func', 'c-macro']
|
|
||||||
reftype_str = ['function', 'macro']
|
|
||||||
|
|
||||||
cdom = app.env.domains['c']
|
cdom = app.env.domains['c']
|
||||||
#
|
#
|
||||||
# Go through the dance of getting an xref out of the C domain
|
# Go through the dance of getting an xref out of the C domain
|
||||||
|
@ -153,15 +150,13 @@ def markup_func_ref_sphinx3(docname, app, match):
|
||||||
|
|
||||||
if base_target not in Skipnames:
|
if base_target not in Skipnames:
|
||||||
for target in possible_targets:
|
for target in possible_targets:
|
||||||
if target not in Skipfuncs:
|
if (target not in Skipfuncs) and not failure_seen(target):
|
||||||
for class_s, reftype_s in zip(class_str, reftype_str):
|
lit_text = nodes.literal(classes=['xref', 'c', 'c-func'])
|
||||||
if failure_seen(target, reftype_s):
|
|
||||||
continue
|
|
||||||
lit_text = nodes.literal(classes=['xref', 'c', class_s])
|
|
||||||
lit_text += target_text
|
lit_text += target_text
|
||||||
pxref = addnodes.pending_xref('', refdomain = 'c',
|
pxref = addnodes.pending_xref('', refdomain = 'c',
|
||||||
reftype = reftype_s,
|
reftype = 'function',
|
||||||
reftarget = target, modname = None,
|
reftarget = target,
|
||||||
|
modname = None,
|
||||||
classname = None)
|
classname = None)
|
||||||
#
|
#
|
||||||
# XXX The Latex builder will throw NoUri exceptions here,
|
# XXX The Latex builder will throw NoUri exceptions here,
|
||||||
|
@ -169,14 +164,14 @@ def markup_func_ref_sphinx3(docname, app, match):
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
xref = cdom.resolve_xref(app.env, docname, app.builder,
|
xref = cdom.resolve_xref(app.env, docname, app.builder,
|
||||||
reftype_s, target, pxref,
|
'function', target, pxref,
|
||||||
lit_text)
|
lit_text)
|
||||||
except NoUri:
|
except NoUri:
|
||||||
xref = None
|
xref = None
|
||||||
|
|
||||||
if xref:
|
if xref:
|
||||||
return xref
|
return xref
|
||||||
note_failure(target, reftype_s)
|
note_failure(target)
|
||||||
|
|
||||||
return target_text
|
return target_text
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче