Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Perl: porters

[PATCH] ParseXS.pm: small optimization for "Usage: ..." constant strings

 

 

Perl porters RSS feed   Index | Next | Previous | View Threaded


at at altlinux

Nov 13, 2006, 6:45 PM

Post #1 of 2 (202 views)
Permalink
[PATCH] ParseXS.pm: small optimization for "Usage: ..." constant strings

Hello,

If you take a look at e.g. POSIX module, you can see a whole lot
of similar "Usage: ..." constant strings.

$ strings auto/POSIX/POSIX.so |grep ^Usage: |head
Usage: POSIX::lchown(uid, gid, path)
Usage: POSIX::getcwd()
Usage: POSIX::ttyname(fd)
Usage: POSIX::sysconf(name)
Usage: POSIX::setuid(uid)
Usage: POSIX::setgid(gid)
Usage: POSIX::pause()
Usage: POSIX::pathconf(filename, name)
Usage: POSIX::fpathconf(fd, name)
Usage: POSIX::cuserid(s = 0)
$ strings auto/POSIX/POSIX.so |grep ^Usage: |wc -l
109
$ strings auto/POSIX/POSIX.so |grep ^Usage: |wc -c
3892
$

Those can be factored to smaller constant strings which will be
optimized by the linker. I rebuilt perl with the following change
and the size of POSIX.so was reduced by 2168 bytes.

Note that "$pname" constant string is already used in newXS()
bootstrap code, so its usage here is effectively free.
---
lib/ExtUtils/ParseXS.pm | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/ExtUtils/ParseXS.pm b/lib/ExtUtils/ParseXS.pm
index dd05661..e9c0de8 100644
--- a/lib/ExtUtils/ParseXS.pm
+++ b/lib/ExtUtils/ParseXS.pm
@@ -596,12 +596,12 @@ EOF
if ($ALIAS)
{ print Q(<<"EOF") if $cond }
# if ($cond)
-# Perl_croak(aTHX_ "Usage: %s($report_args)", GvNAME(CvGV(cv)));
+# Perl_croak(aTHX_ "Usage: %s(%s)", GvNAME(CvGV(cv)), "$report_args");
EOF
else
{ print Q(<<"EOF") if $cond }
# if ($cond)
-# Perl_croak(aTHX_ "Usage: $pname($report_args)");
+# Perl_croak(aTHX_ "Usage: %s(%s)", "$pname", "$report_args");
EOF

# cv doesn't seem to be used, in most cases unless we go in
--
1.4.3.GIT


rgarciasuarez at gmail

Nov 14, 2006, 1:41 AM

Post #2 of 2 (163 views)
Permalink
Re: [PATCH] ParseXS.pm: small optimization for "Usage: ..." constant strings [In reply to]

On 14/11/06, Alexey Tourbin <at[at]altlinux.ru> wrote:
> Hello,
>
> If you take a look at e.g. POSIX module, you can see a whole lot
> of similar "Usage: ..." constant strings.
>
> $ strings auto/POSIX/POSIX.so |grep ^Usage: |head
> Usage: POSIX::lchown(uid, gid, path)
> Usage: POSIX::getcwd()
> Usage: POSIX::ttyname(fd)
> Usage: POSIX::sysconf(name)
> Usage: POSIX::setuid(uid)
> Usage: POSIX::setgid(gid)
> Usage: POSIX::pause()
> Usage: POSIX::pathconf(filename, name)
> Usage: POSIX::fpathconf(fd, name)
> Usage: POSIX::cuserid(s = 0)
> $ strings auto/POSIX/POSIX.so |grep ^Usage: |wc -l
> 109
> $ strings auto/POSIX/POSIX.so |grep ^Usage: |wc -c
> 3892
> $
>
> Those can be factored to smaller constant strings which will be
> optimized by the linker. I rebuilt perl with the following change
> and the size of POSIX.so was reduced by 2168 bytes.
>
> Note that "$pname" constant string is already used in newXS()
> bootstrap code, so its usage here is effectively free.
> ---
> lib/ExtUtils/ParseXS.pm | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/ExtUtils/ParseXS.pm b/lib/ExtUtils/ParseXS.pm
> index dd05661..e9c0de8 100644
> --- a/lib/ExtUtils/ParseXS.pm
> +++ b/lib/ExtUtils/ParseXS.pm
> @@ -596,12 +596,12 @@ EOF
> if ($ALIAS)
> { print Q(<<"EOF") if $cond }
> # if ($cond)
> -# Perl_croak(aTHX_ "Usage: %s($report_args)", GvNAME(CvGV(cv)));
> +# Perl_croak(aTHX_ "Usage: %s(%s)", GvNAME(CvGV(cv)), "$report_args");
> EOF
> else
> { print Q(<<"EOF") if $cond }
> # if ($cond)
> -# Perl_croak(aTHX_ "Usage: $pname($report_args)");
> +# Perl_croak(aTHX_ "Usage: %s(%s)", "$pname", "$report_args");
> EOF
>
> # cv doesn't seem to be used, in most cases unless we go in

Nice trick. Thanks, applied as change #29269 to bleadperl.

Perl porters RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.