This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
mktables: Avoid some work
authorKarl Williamson <khw@cpan.org>
Tue, 21 Nov 2017 18:44:11 +0000 (11:44 -0700)
committerKarl Williamson <khw@cpan.org>
Thu, 23 Nov 2017 21:18:51 +0000 (14:18 -0700)
Some tables generated by this program are completely described as the
complements of other tables.  There is no need to thus generate them, as
when their value is needed, they can be generated from the other one.
However, this takes time, and so this commit caches the result the first
time it is needed, and returns that for any future needs.

This must not be done until after the controlling table is fully
populated, or else the cache would have to be invalidated.  Since there
is unlikely to be the need for getting the value before the populating
is one, What is done here is to simply lock the controlling table, so
that any attempt to change it will raise an error, and the code can be
fixed at that time, if the need ever does arise.

charclass_invlists.h
lib/unicore/mktables
regcharclass.h

index 4eb26ef..69b42b3 100644 (file)
@@ -97454,7 +97454,7 @@ static const U8 WB_table[24][24] = {
  * be0f129691d479aa38646e4ca0ec1ee576ae7f75b0300a5624a7fa862fa8abba lib/unicore/extracted/DLineBreak.txt
  * 92449d354d9f6b6f2f97a292ebb59f6344ffdeb83d120d7d23e569c43ba67cd5 lib/unicore/extracted/DNumType.txt
  * e3a319527153b0c6c0c549b40fc6f3a01a7a0dcd6620784391db25901df3b154 lib/unicore/extracted/DNumValues.txt
- * d905c655c0cc448f19894613ce87026dea667bb66c65937667424fc0afdc90c4 lib/unicore/mktables
+ * c145400bb109fc28371c48e1fcde2e55d44c35ac561b38613cfd7ed235ceead3 lib/unicore/mktables
  * 21653d2744fdd071f9ef138c805393901bb9547cf3e777ebf50215a191f986ea lib/unicore/version
  * 913d2f93f3cb6cdf1664db888bf840bc4eb074eef824e082fceda24a9445e60c regen/charset_translations.pl
  * 48418cbf454eb9ef35c73468ed5ef72ad8603490eabe74181ce4fae42ec72579 regen/mk_invlists.pl
index 200ae46..be4d81d 100644 (file)
@@ -8012,13 +8012,23 @@ sub trace { return main::trace(@_); }
         # complement's if it has one.
 
         my $self = shift;
-        my $complement;
-        if (($complement = $self->complement) != 0) {
-            return ~ $complement->_range_list;
-        }
-        else {
-            return $self->SUPER::_range_list;
-        }
+        my $complement = $self->complement;
+
+        # In order to avoid re-complementing on each access, only do the
+        # complement the first time, and store the result in this table's
+        # range list to use henceforth.  However, this wouldn't work if the
+        # controlling (complement) table changed after we do this, so lock it.
+        # Currently, the value of the complement isn't needed until after it
+        # is fully constructed, so this works.  If this were to change, the
+        # each_range iteration functionality would no longer work on this
+        # complement.
+        if ($complement != 0 && $self->SUPER::_range_list->count == 0) {
+            $self->_set_range_list($self->SUPER::_range_list
+                                + ~ $complement->_range_list);
+            $complement->lock;
+        }
+
+        return $self->SUPER::_range_list;
     }
 
     sub add_alias {
index 38ddd84..a03eacc 100644 (file)
  * be0f129691d479aa38646e4ca0ec1ee576ae7f75b0300a5624a7fa862fa8abba lib/unicore/extracted/DLineBreak.txt
  * 92449d354d9f6b6f2f97a292ebb59f6344ffdeb83d120d7d23e569c43ba67cd5 lib/unicore/extracted/DNumType.txt
  * e3a319527153b0c6c0c549b40fc6f3a01a7a0dcd6620784391db25901df3b154 lib/unicore/extracted/DNumValues.txt
- * d905c655c0cc448f19894613ce87026dea667bb66c65937667424fc0afdc90c4 lib/unicore/mktables
+ * c145400bb109fc28371c48e1fcde2e55d44c35ac561b38613cfd7ed235ceead3 lib/unicore/mktables
  * 21653d2744fdd071f9ef138c805393901bb9547cf3e777ebf50215a191f986ea lib/unicore/version
  * 913d2f93f3cb6cdf1664db888bf840bc4eb074eef824e082fceda24a9445e60c regen/charset_translations.pl
  * 9ea6338945a7d70e5ea4b31ac7856c0b521df96be002e94b4b3b7d31debbf3ab regen/regcharclass.pl