This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Use values if known at compile time
authorKarl Williamson <public@khwilliamson.com>
Sat, 15 Dec 2012 04:43:14 +0000 (21:43 -0700)
committerKarl Williamson <public@khwilliamson.com>
Sat, 22 Dec 2012 18:11:29 +0000 (11:11 -0700)
When compiling a regular expression, it is too expensive to go out and
load from disk the list of code points that match a particular Posix
character class.  Some of these classes have so few code points, that
the lists are compiled in, but others are too large for that, for
example the list of code points that match \w.  (Also, it is known at
compile time which of the 256 code points within the Latin-1 range match
any Posix character class.)

The lists for beyond Latin-1 are demand-loaded upon first need for each,
thus the loading is deferred to execution time.  This is less efficient
than doing it at compilation time, but many many programs will never need
to load them, so the deferral is a big gain.  However, once loaded, they
stay loaded (in the current and all sub threads).  It may be that at the
time a regex is being compiled that a list it needs has already been
loaded for some other reason.  Then, the data is already available for
free, and this commit changes to use it for most Posix character
classes, and their complements.  This method replaces one that was
instituted just a few commits ago (I can't refer to its commit number,
because it is subject to change before the final push to blead; but it
has the same title as this commit.)

Future commits will expand the number of classes that use the mechanism
started in this commit

regcomp.c

index 6b7104f..41870a3 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -11933,9 +11933,16 @@ parseit:
                case ANYOF_PRINT:
                case ANYOF_PUNCT:
                case ANYOF_WORDCHAR:
+                    if ( !  PL_utf8_swash_ptrs[classnum]) {
                    DO_POSIX_LATIN1_ONLY_KNOWN(ret, namedclass, posixes,
                         PL_Posix_ptrs[classnum], PL_utf8_swash_ptrs[classnum], PL_L1Posix_ptrs[classnum], swash_property_names[classnum], listsv);
                    break;
+                    }
+                    if (! PL_XPosix_ptrs[classnum]) {
+                        PL_XPosix_ptrs[classnum]
+                            = _swash_to_invlist(PL_utf8_swash_ptrs[classnum]);
+                    }
+                    /* FALL THROUGH */
 
                case ANYOF_CNTRL:
                case ANYOF_PSXSPC:
@@ -11951,10 +11958,17 @@ parseit:
                case ANYOF_NPRINT:
                case ANYOF_NPUNCT:
                case ANYOF_NWORDCHAR:
+                    if ( !  PL_utf8_swash_ptrs[classnum]) {
                    DO_N_POSIX_LATIN1_ONLY_KNOWN(ret, namedclass, posixes,
                         PL_Posix_ptrs[classnum], PL_L1Posix_ptrs[classnum], swash_property_names[classnum], listsv,
                         runtime_posix_matches_above_Unicode);
                    break;
+                    }
+                    if (! PL_XPosix_ptrs[classnum]) {
+                        PL_XPosix_ptrs[classnum]
+                            = _swash_to_invlist(PL_utf8_swash_ptrs[classnum]);
+                    }
+                    /* FALL THROUGH */
 
                case ANYOF_NCNTRL:
                case ANYOF_NPSXSPC: