• Robert Bradshaw's avatar
    Cache __builtin__ name lookups so they are performed on module load rather than at every use. · 6fd9a195
    Robert Bradshaw authored
    The code "__Pyx_GetName(__pyx_b, __pyx_n_[string])" is performed in several
    thousand places throughout the sage library, and can be quite expensive
    (a dictionary lookup, possibly raising an error, etc.) This is redundant
    as the result will always be the same. I perform the lookup once
    (on loading the module), then have a pointer to the result for all subsequent use.
    
    The most common examples are bool/str/int (both as function calls and
    in isinstance), True/False, and raisign errors.
    
    A side feature is that on loading a module with an illegal __builtin__ name,
    it will complain at load time rather than at run time.
    6fd9a195
Options.py 201 Bytes