Docs: improve online manual lookup time time #104581

Closed
Erik Abrahamsson wants to merge 3 commits from erik85/blender:online-help-improve-time into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 14 additions and 0 deletions

View File

@ -1249,7 +1249,21 @@ class WM_OT_doc_view_manual(Operator):
# XXX, for some reason all RNA ID's are stored lowercase
# Adding case into all ID's isn't worth the hassle so force lowercase.
rna_id = rna_id.lower()
import re
# Match characters that have a special meaning to `fnmatch`.
# The characters that can occur as the first special character are `*?[`.
# If any of these are used we must let `fnmatch` run its own matching logic.
# However, in most cases a literal prefix is used making it considerably faster
# to do a simple `startswith` check before performing a full match, see #104581.
erik85 marked this conversation as resolved
Review

* should be escaped, suggest: r"^[^?\*\[]+" - with a comment for clarity.

# Match any character not in `*?[`.
re_match_non_special = re.compile(r"^[^?\*\[]+").match
`*` should be escaped, suggest: `r"^[^?\*\[]+"` - with a comment for clarity. ``` # Match any character not in `*?[`. re_match_non_special = re.compile(r"^[^?\*\[]+").match ```
re_match_non_special = re.compile(r"^[^?\*\[]+").match
for pattern, url_suffix in url_mapping:
# Simple optimization, makes a big difference (over 50x speedup).
non_special = re_match_non_special(pattern)
erik85 marked this conversation as resolved
Review

Avoid calling non_special.end() twice, either assign a variable or remove, as (not rna_id.startswith(pattern[:non_special.end()]))) on it's own works as expected without the need to check end() > 0.

Avoid calling `non_special.end()` twice, either assign a variable or remove, as `(not rna_id.startswith(pattern[:non_special.end()])))` on it's own works as expected without the need to check `end() > 0`.
if non_special is None or not rna_id.startswith(pattern[:non_special.end()]):
continue
if fnmatchcase(rna_id, pattern):
if verbose:
print(" match found: '%s' --> '%s'" % (pattern, url_suffix))