in reply to Re: How is redefining a sub internally done?
in thread How is redefining a sub internally done?
However as an optimisation, GVs which only have their CV slot used, are instead created as an RV to a CV. So for example, for
at compile time, the value of the hash entry $FOO::{f} is created as an RV to the CV associated with f, rather than as a full typeglob. When the GV op is compiled, it points to that RV. When the GV op is called, it pushes that RV onto the stack. When the ENTERSUB is is called, it pops that value, notices that it's an RV rather than a GV, and extracts the CV as the thing referenced.package FOO; sub f { ... } f()
When things get more complex, the 'RV to a CV' SV is upgraded to a full GV with the CV in its code slot.
An 'RV to CV' is smaller and quicker than a full GV (a GV points to a GP which has a CV slot - so two allocations, two dereferences).
Dave.
|
|---|