Docs: improve online manual lookup time time #104581
|
@ -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
|
||||
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
Campbell Barton
commented
Avoid calling 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))
|
||||
|
|
Loading…
Reference in New Issue
*
should be escaped, suggest:r"^[^?\*\[]+"
- with a comment for clarity.