Skip to content

Commit

Permalink
Indentation code generation optimization.
Browse files Browse the repository at this point in the history
This commit significantly optimizes usage of indentation (i.e., semantic
whitespace) throughout code snippets dynamically generated by
@beartype's type-checking code generator. Since strings are expensive to
repeatedly generate, @beartype now internally caches and reuses
frequently used indentation. In truth, this means nothing. But @leycec
just *had* to do this to satisfy his aberrant OCD disorder. I swear! It
isn't my fault! It's fast or it ain't @beartype. (*Ophthalmology or optimality!?*)
  • Loading branch information
leycec committed Mar 7, 2024
1 parent b9c1ddc commit 1f419dc
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 197 deletions.
9 changes: 5 additions & 4 deletions beartype/_check/code/codemagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@
'''


HINT_META_INDEX_INDENT = next(__hint_meta_index_counter)
HINT_META_INDEX_INDENT_LEVEL = next(__hint_meta_index_counter)
'''
0-based index into each tuple of hint metadata providing **current
indentation** (i.e., Python code snippet expanding to the current level of
indentation appropriate for the currently visited hint).
0-based index into each tuple of hint metadata providing the **current
indentation level** (i.e., 1-based positive integer describing the current level
of indentation appropriate for the currently visited hint).
'''


# Delete the above counter for safety and sanity in equal measure.
del __hint_meta_index_counter

0 comments on commit 1f419dc

Please sign in to comment.