develooper Front page | perl.perl5.porters | Postings from August 2017

[perl #129990] Reduce malloc&free for S_parse_gv_stash_name

Thread Previous
From:
Tony Cook via RT
Date:
August 31, 2017 04:10
Subject:
[perl #129990] Reduce malloc&free for S_parse_gv_stash_name
Message ID:
rt-4.0.24-6825-1504152609-1723.129990-15-0@perl.org
On Thu, 27 Apr 2017 11:32:02 -0700, atoomic wrote:
> Attached are the two patches, and here is a bench using Tony idea +
> some extra tests.
> Can also view the patches on github:
> https://github.com/atoomic/perl5/commits/devel/blead_S_parse_gv_stash_name

Sorry I lost this ticket.

There's a couple of issues with the second patch:

1) there's no tests that use the longer allocated buffer.  This includes existing tests. From a gcov run:

       14: 1635:                    if ( *len+2 <= sizeof smallbuf)
       14: 1636:                        tmpbuf = smallbuf;
        -: 1637:                    else {
        -: 1638:                        /* only malloc once if needed */
    #####: 1639:                        if (tmpfullbuf == NULL) /* only malloc&free once, a little more than needed */
    #####: 1640:                            Newx(tmpfullbuf, full_len+2, char);
    #####: 1641:                        tmpbuf = tmpfullbuf;
        -: 1642:                    }
       14: 1643:                    Copy(*name, tmpbuf, *len, char);

2) You have this code in a couple of places:

 if ( tmpfullbuf != smallbuf )
     Safefree(tmpfullbuf);

but this condition is always true (tmpfullbuf can be NULL or allocated, it's never smallbuf).

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=129990

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About