On Sat, May 16, 2015 at 11:08 AM, Nick Wellnhofer <[email protected]> wrote:
> I created a branch that simplifies the way we enable operator overloading > for Perl objects. Overloading is now activated for all objects because it's > a much cheaper operation than the original code assumed. It's actually a > no-op with recent Perls. > > https://github.com/nwellnhof/lucy-clownfish/commits/enable_overload +1 to proceed with this line of simplification! However, I tried this branch on Perl 5.12.5 and some of the overloading tests failed. Removing the call to Gv_AMupdate seems to pose a problem on earlier Perls. Also, it seems to be a problem to enable overloading on *all* objects under earlier Perls. Here are fixes: https://github.com/rectang/lucy-clownfish/commits/enable_overload > All of this could be simplified by replacing S_lazy_init_host_obj with > sv_bless. It seems that Clownfish had to create the inner Perl objects > without the outer reference at some point, but this doesn't seem to be > necessary anymore. The motivation for using only the inner object is that the outer object simply is not needed. Creating it takes some amount of time and keeping it occupies some amount of memory. It's possible to use sv_bless instead of the current rig -- you just extract the inner object, incref it and assign it to self->ref.host_obj, then decref the outer object. One of the commits on my branch shows how to do this -- it uses sv_setref_pv, which calls sv_bless internally. The cost of creating and immediately destroying the RV is presumably worth the benefit in reduced code complexity. Marvin Humphrey
