• Jason Rhinelander's avatar
    Lazy instance value pointer allocation · fd81a03e
    Jason Rhinelander authored
    We currently allocate instance values when creating the instance itself
    (except when constructing the instance for a `cast()`), but there is no
    particular reason to do so: the instance itself and the internals (for
    a non-simple layout) are allocated via Python, with no reason to
    expect better locality from the invoked `operator new`.  Moreover, it
    makes implementation of factory function constructors trickier and
    slightly less efficient: they don't use the pre-eallocate the memory,
    which means there is a pointless allocation and free.
    
    This commit makes the allocation lazy: instead of preallocating when
    creating the instance, the allocation happens when the instance is
    first loaded (if null at that time).
    
    In addition to making it more efficient to deal with cases that don't
    need preallocation, this also allows for a very slight performance
    increase by not needing to look up the instances types during
    allocation.  (There is a lookup during the eventual load, of course, but
    that is happening already).
    fd81a03e
cast.h 86.3 KB