zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
U
Þ=®drã@s`dZddlZddlmZddlmZejr6ddlm    Z    ej
dej
dœd    d
„Z Gd d „d eƒZ dS) a¯The optimizer tries to constant fold expressions and modify the AST
in place so that it should be faster to evaluate.
 
Because the AST does not contain all the scoping information and the
compiler has to find that out, we cannot do all the optimizations we
want. For example, loop unrolling doesn't work because unrolled loops
would have a different scope. The solution would be a second syntax tree
that stored the scoping rules.
éNé)Únodes)ÚNodeTransformer)Ú Environmentr)ÚnodeÚ environmentÚreturncCst|ƒ}t tj| |¡¡S)z^The context hint can be used to perform an static optimization
    based on the context given.)Ú    OptimizerÚtÚcastrÚNodeÚvisit)rrZ    optimizer©rúGd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\jinja2/optimizer.pyÚoptimizesrcs@eZdZdddœdd„Zejejejejdœ‡fdd„ Z‡Z    S)    r    zt.Optional[Environment]N)rrcCs
||_dS)N)r)ÚselfrrrrÚ__init__szOptimizer.__init__)rÚargsÚkwargsrcsftƒj|f|ž|Ž}t|tjƒrbz*tjj| |r8|dnd¡|j|j    dWStj
k
r`YnX|S)Nr)Úlinenor) ÚsuperÚ generic_visitÚ
isinstancerZExprZConstZfrom_untrustedZas_constrrZ
Impossible)rrrr©Ú    __class__rrrs ýzOptimizer.generic_visit)
Ú__name__Ú
__module__Ú __qualname__rrr r
ÚAnyrÚ __classcell__rrrrr    s þr    ) Ú__doc__Útypingr
ÚrZvisitorrÚ TYPE_CHECKINGrrr rr    rrrrÚ<module>s