This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
File::Glob: short-circuit earlier for list cx
authorFather Chrysostomos <sprout@cpan.org>
Thu, 27 Oct 2011 07:28:02 +0000 (00:28 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 27 Oct 2011 07:28:02 +0000 (00:28 -0700)
For <...> without spaces in list context, don’t even bother adding
file names returned by the glob engine to the cached array.  I origin-
ally added a short-circuit that would skip copying the file names from
the cached array on to the stack in that case, because the file names
are already there.  But we can also skip putting them in the array to
begin with, as the cached array is about to be deleted.

This should make things even faster.

ext/File-Glob/Glob.xs

index 830bb8c..9d35ac2 100644 (file)
@@ -224,10 +224,10 @@ csh_glob(pTHX)
            {
                dMARK;
                dORIGMARK;
-               while (++MARK <= SP)
-                   av_push(entries, SvREFCNT_inc_simple_NN(*MARK));
                /* short-circuit here for a fairly common case */
                if (!patav && gimme == G_ARRAY) goto return_list;
+               while (++MARK <= SP)
+                   av_push(entries, SvREFCNT_inc_simple_NN(*MARK));
 
                SP = ORIGMARK;
            }