texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[6477] texi2any faster startup


From: Gavin D. Smith
Subject: [6477] texi2any faster startup
Date: Tue, 28 Jul 2015 15:05:13 +0000

Revision: 6477
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6477
Author:   gavin
Date:     2015-07-28 15:05:11 +0000 (Tue, 28 Jul 2015)
Log Message:
-----------
texi2any faster startup

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/tp/Texinfo/Convert/Info.pm
    trunk/tp/Texinfo/Convert/Plaintext.pm
    trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm
    trunk/tp/texi2any.pl

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2015-07-27 19:05:31 UTC (rev 6476)
+++ trunk/ChangeLog     2015-07-28 15:05:11 UTC (rev 6477)
@@ -1,3 +1,15 @@
+2015-07-28  Gavin Smith  <address@hidden>
+
+       * tp/texi2any.pl: Import fewer modules by default, for speed.  
+       (texi2any --help changed from about 0.4 s to about 0.1 s.).
+       (%formats_table): Store name of required module in 'module' 
+       values of hashes.
+       * tp/Texinfo/Convert/XSParagraph/XSParagraph.pm: Add
+       "require Texinfo::Convert::Paragraph" for fall-back code.
+       * tp/Texinfo/Convert/Plaintext.pm,
+       * tp/Texinfo/Convert/Info.pm: Use Texinfo/Convert/Paragraph.pm 
+       indirectly via Texinfo/Convert/XSParagraph/XSParagraph.pm.
+
 2015-07-27  Gavin Smith  <address@hidden>
 
        * tp/Texinfo/Convert/XSParagraph/XSParagraph.xs

Modified: trunk/tp/Texinfo/Convert/Info.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Info.pm    2015-07-27 19:05:31 UTC (rev 6476)
+++ trunk/tp/Texinfo/Convert/Info.pm    2015-07-28 15:05:11 UTC (rev 6477)
@@ -304,7 +304,7 @@
   my $self = shift;
 
   $self->_set_global_multiple_commands();
-  my $paragraph = Texinfo::Convert::Paragraph->new();
+  my $paragraph = XSParagraph->new();
   my $result = $paragraph->add_text("This is ");
   # This ensures that spaces in file are kept.
   $result .= $paragraph->add_next($self->{'output_filename'});

Modified: trunk/tp/Texinfo/Convert/Plaintext.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Plaintext.pm       2015-07-27 19:05:31 UTC (rev 
6476)
+++ trunk/tp/Texinfo/Convert/Plaintext.pm       2015-07-28 15:05:11 UTC (rev 
6477)
@@ -26,12 +26,11 @@
 use Texinfo::Convert::Converter;
 use Texinfo::Common;
 use Texinfo::Convert::Texinfo;
+use XSParagraph;
 use Texinfo::Convert::Text;
-use Texinfo::Convert::Paragraph;
 use Texinfo::Convert::Line;
 use Texinfo::Convert::UnFilled;
 
-use XSParagraph;
 
 use Carp qw(cluck);
 

Modified: trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm
===================================================================
--- trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm 2015-07-27 19:05:31 UTC 
(rev 6476)
+++ trunk/tp/Texinfo/Convert/XSParagraph/XSParagraph.pm 2015-07-28 15:05:11 UTC 
(rev 6477)
@@ -1,7 +1,19 @@
 # Copyright 2014, 2015 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License,
+# or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package XSParagraph;
-require DynaLoader;
 
 use DynaLoader;
 
@@ -142,6 +154,7 @@
 
 FALLBACK:
   # Fall back to using the Perl code.
+  require Texinfo::Convert::Paragraph;
   *XSParagraph:: = *Texinfo::Convert::Paragraph::;
 DONTFALLBACK: ;
 } # end BEGIN

Modified: trunk/tp/texi2any.pl
===================================================================
--- trunk/tp/texi2any.pl        2015-07-27 19:05:31 UTC (rev 6476)
+++ trunk/tp/texi2any.pl        2015-07-28 15:05:11 UTC (rev 6477)
@@ -111,21 +111,10 @@
       unshift @INC, (File::Spec->catdir($lib_dir, 'lib', 'Text-Unidecode', 
'lib'));
     }
   }
-}
+} # end BEGIN
 
-use Texinfo::Convert::Texinfo;
-use Texinfo::Parser;
-use Texinfo::Structuring;
-use Texinfo::Convert::Info;
-use Texinfo::Convert::HTML;
-use Texinfo::Convert::TexinfoXML;
-use Texinfo::Convert::TexinfoSXML;
-use Texinfo::Convert::DocBook;
-use Texinfo::Convert::TextContent;
-use Texinfo::Convert::PlainTexinfo;
-use Texinfo::Convert::IXINSXML;
-use DebugTexinfo::DebugCount;
-use DebugTexinfo::DebugTree;
+use Locale::Messages;
+use Texinfo::Common;
 
 my ($real_command_name, $command_directory, $command_suffix) 
    = fileparse($0, '.pl');
@@ -290,6 +279,7 @@
   } else {
     # used in the standalone perl module, as $hardcoded_version is undef
     # and it should never be configured in that setup
+    require Texinfo::Parser;
     $configured_version = $Texinfo::Parser::VERSION;
   }
 }
@@ -392,6 +382,7 @@
 
 sub _load_init_file($) {
   my $file = shift;
+  require Texinfo::Convert::HTML;
   eval { require($file) ;};
   my $e = $@;
   if ($e ne '') {
@@ -564,13 +555,13 @@
  'info' => {
              'nodes_tree' => 1,
              'floats' => 1,
-             'converter' => sub{Texinfo::Convert::Info->converter(@_)},
+             'module' => 'Texinfo::Convert::Info'
            },
   'plaintext' => {
              'nodes_tree' => 1,
              'floats' => 1,
              'split' => 1,
-             'converter' => sub{Texinfo::Convert::Plaintext->converter(@_)},
+             'module' => 'Texinfo::Convert::Plaintext'
            },
   'html' => {
              'nodes_tree' => 1,
@@ -580,26 +571,26 @@
              'simple_menu' => 1,
              'move_index_entries_after_items' => 1,
              'no_warn_non_empty_parts' => 1,
-             'converter' => sub{Texinfo::Convert::HTML->converter(@_)},
+             'module' => 'Texinfo::Convert::HTML'
            },
   'texinfoxml' => {
              'nodes_tree' => 1,
-             'converter' => sub{Texinfo::Convert::TexinfoXML->converter(@_)},
+             'module' => 'Texinfo::Convert::TexinfoXML',
              'floats' => 1,
            },
   'texinfosxml' => {
              'nodes_tree' => 1,
-             'converter' => sub{Texinfo::Convert::TexinfoSXML->converter(@_)},
+             'module' => 'Texinfo::Convert::TexinfoSXML',
              'floats' => 1,
            },
   'ixinsxml' => {
              'nodes_tree' => 1,
-             'converter' => sub{Texinfo::Convert::IXINSXML->converter(@_)},
+             'module' => 'Texinfo::Convert::IXINSXML'
            },
   'docbook' => {
              'move_index_entries_after_items' => 1,
              'no_warn_non_empty_parts' => 1,
-             'converter' => sub{Texinfo::Convert::DocBook->converter(@_)},
+             'module' => 'Texinfo::Convert::DocBook'
            },
   'pdf' => {
              'texi2dvi_format' => 1,
@@ -616,11 +607,11 @@
   'debugcount' => {
              'nodes_tree' => 1,
              'floats' => 1,
-             'converter' => sub{DebugTexinfo::DebugCount->converter(@_)},
+             'converter' => 'DebugTexinfo::DebugCount'
            },
   'debugtree' => {
           'split' => 1,
-          'converter' => sub{DebugTexinfo::DebugTree->converter(@_)},
+          'converter' => 'DebugTexinfo::DebugTree'
          },
   'textcontent' => {
             'converter' => sub{Texinfo::Convert::TextContent->converter(@_)},
@@ -1083,6 +1074,11 @@
   document_warn(__('--Xopt option without printed output')); 
 }
 
+require Texinfo::Parser;
+require Texinfo::Structuring;
+# Avoid loading these modules until down here to speed up the case
+# when they are not needed.
+
 my %tree_transformations;
 if (get_conf('TREE_TRANSFORMATIONS')) {
   my @transformations = split /,/, get_conf('TREE_TRANSFORMATIONS');
@@ -1109,6 +1105,15 @@
 
 my $converter_class;
 my %converter_defaults;
+
+if (defined($formats_table{$format}->{'module'})) {
+  # Speed up initialization by only loading the module we need.
+  eval "require $formats_table{$format}->{'module'};";
+  eval '$formats_table{$format}->{\'converter\'} = sub{'.
+                $formats_table{$format}->{'module'}
+        .'->converter(@_)};';
+}
+
 # This gets the class right, even though there is a sub...
 if (defined($formats_table{$format}->{'converter'})) {
   $converter_class = ref(&{$formats_table{$format}->{'converter'}});
@@ -1241,6 +1246,7 @@
   }
 
   if (defined(get_conf('MACRO_EXPAND')) and $file_number == 0) {
+    require Texinfo::Convert::Texinfo;
     my $texinfo_text = Texinfo::Convert::Texinfo::convert($tree, 1);
     #print STDERR "$texinfo_text\n";
     my $macro_expand_file = get_conf('MACRO_EXPAND');




reply via email to

[Prev in Thread] Current Thread [Next in Thread]