Skip to content

Commit

Permalink
perf: only get stddomain terms once by document
Browse files Browse the repository at this point in the history
  • Loading branch information
n-peugnet committed Jun 27, 2022
1 parent 747efb2 commit e4618ea
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions _ext/term_tooltips.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class TermTooltips(SphinxPostTransform):
logger = logging.getLogger('term_tooltips')

def run(self) -> None:
# Get dictionary of terms from the standard domain.
stddomain = self.env.get_domain('std')
self.stdterms = stddomain.data.setdefault('terms', {})
for termref in self.document.findall(nodes.reference):
if isinstance(termref[0], nodes.Inline) and 'std-term' in termref[0]['classes']:
self.logger.debug(f'found termref: {termref}')
Expand All @@ -21,13 +24,10 @@ def process_termref(self, termref: nodes.reference) -> None:
# If 'refid' is not defined, then the ref is from another document
# and we need to find it from the standard domain.
if refid == '':
# Get dictionary of terms from the standard domain.
stddomain = self.env.get_domain('std')
stdterms = stddomain.data.setdefault('terms', {})
# Get key from termref's text.
reftext: str = termref.astext().lower()
# Get object from dictionary of terms.
obj = stdterms.get(reftext, None)
obj = self.stdterms.get(reftext, None)
if obj == None:
self.logger.warning(f'could not find object in std domain for reftext: "{reftext}"')
return
Expand Down

0 comments on commit e4618ea

Please sign in to comment.