[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[6255] Plaintext.pm faster byte counting
From: |
Gavin D. Smith |
Subject: |
[6255] Plaintext.pm faster byte counting |
Date: |
Thu, 07 May 2015 02:06:20 +0000 |
Revision: 6255
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6255
Author: gavin
Date: 2015-05-07 02:06:19 +0000 (Thu, 07 May 2015)
Log Message:
-----------
Plaintext.pm faster byte counting
Modified Paths:
--------------
trunk/ChangeLog
trunk/tp/DebugTexinfo/DebugCount.pm
trunk/tp/Texinfo/Convert/Info.pm
trunk/tp/Texinfo/Convert/Plaintext.pm
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2015-05-06 22:03:58 UTC (rev 6254)
+++ trunk/ChangeLog 2015-05-07 02:06:19 UTC (rev 6255)
@@ -1,3 +1,22 @@
+2015-05-07 Gavin Smith <address@hidden>
+
+ * tp/Texinfo/Convert/Plaintext.pm (_add_text_count)
+ (_count_added): Don't call Texinfo::Common::count_bytes, collect
+ the argument instead into a string.
+ (_update_count_context): Count the text collected in
+ _add_text_count.
+
+ * tp/Texinfo/Convert/Plaintext.pm (add_location)
+ (_update_locations_counts, _align_environment, _node_line)
+ (_printindex_formatted, _convert),
+ * tp/Texinfo/Convert/Info.pm (output),
+ * tp/DebugTexinfo/DebugCount.pm (_convert):
+ Call _update_count_context before accessing 'bytes' value of
+ current count context.
+
+ * tp/Texinfo/Convert/Plaintext.pm (_count_added): Access
+ 'end_line_count' value on hash directly instead of via function
+ call.
2015-05-06 Karl Berry <address@hidden>
* doc/texinfo.tex (\ensuremath): new helper macro.
Modified: trunk/tp/DebugTexinfo/DebugCount.pm
===================================================================
--- trunk/tp/DebugTexinfo/DebugCount.pm 2015-05-06 22:03:58 UTC (rev 6254)
+++ trunk/tp/DebugTexinfo/DebugCount.pm 2015-05-07 02:06:19 UTC (rev 6255)
@@ -34,6 +34,7 @@
$self->{'level'}++;
$self->{'command_type_nr'}++;
+ $self->_update_count_context();
my $bytes_before = $self->{'count_context'}->[-1]->{'bytes'};
my $number_before =
"($self->{'count_context'}->[-1]->{'bytes'},$self->{'count_context'}->[-1]->{'lines'})";
my $command_nr = '['.$self->{'command_type_nr'}.']';
@@ -88,6 +89,7 @@
}
#push @{$self->{'debug_count_strings'}}, ' ' x $self->{'level'}. "TEXT:
$text|\n"
# if ($self->{'count_context'}->[-1]->{'bytes'} > $bytes_before);
+ $self->_update_count_context();
my $number_after =
"($self->{'count_context'}->[-1]->{'bytes'},$self->{'count_context'}->[-1]->{'lines'})";
my $string_after = ' ' x $self->{'level'}. "$command_nr $number_after\n";
$string_after .= " locations $all_locations_string"
Modified: trunk/tp/Texinfo/Convert/Info.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Info.pm 2015-05-06 22:03:58 UTC (rev 6254)
+++ trunk/tp/Texinfo/Convert/Info.pm 2015-05-07 02:06:19 UTC (rev 6255)
@@ -148,6 +148,7 @@
} else {
$result .= $node_text;
}
+ $self->_update_count_context();
if (defined($self->get_conf('SPLIT_SIZE'))
and $self->{'count_context'}->[-1]->{'bytes'} >
$out_file_nr * $self->get_conf('SPLIT_SIZE')
@@ -205,6 +206,7 @@
return undef;
}
print $fh $complete_header;
+ $self->_update_count_context();
$self->{'count_context'}->[-1]->{'bytes'} += $complete_header_bytes;
push @indirect_files, [$self->{'output_filename'}.'-'.$out_file_nr,
$self->{'count_context'}->[-1]->{'bytes'}];
Modified: trunk/tp/Texinfo/Convert/Plaintext.pm
===================================================================
--- trunk/tp/Texinfo/Convert/Plaintext.pm 2015-05-06 22:03:58 UTC (rev
6254)
+++ trunk/tp/Texinfo/Convert/Plaintext.pm 2015-05-07 02:06:19 UTC (rev
6255)
@@ -717,9 +717,10 @@
{
my $self = shift;
my $text = shift;
- $self->{'count_context'}->[-1]->{'bytes'}
- += Texinfo::Common::count_bytes($self, $text,
- $self->{'output_perl_encoding'});
+ if (!$self->{'count_context'}->[-1]->{'pending_text'}) {
+ $self->{'count_context'}->[-1]->{'pending_text'} = '';
+ }
+ $self->{'count_context'}->[-1]->{'pending_text'} .= $text;
}
sub _add_lines_count($$)
@@ -729,6 +730,22 @@
$self->{'count_context'}->[-1]->{'lines'} += $lines_count;
}
+# Update $SELF->{'count_context'}->[-1]->{'bytes'} by counting the text that
+# hasn't been counted yet. It is faster to count the text all together than
+# piece by piece in _add_text_count.
+sub _update_count_context($)
+{
+ my $self = shift;
+ if ($self->{'count_context'}->[-1]->{'pending_text'}) {
+ $self->{'count_context'}->[-1]->{'bytes'} +=
+ Texinfo::Common::count_bytes($self,
+ $self->{'count_context'}->[-1]->{'pending_text'},
+ $self->{'output_perl_encoding'});
+ $self->{'count_context'}->[-1]->{'pending_text'} = '';
+ }
+}
+
+# Save the line and byte offset of $ROOT.
sub _add_location($$)
{
my $self = shift;
@@ -736,8 +753,8 @@
my $location = { 'lines' => $self->{'count_context'}->[-1]->{'lines'} };
push @{$self->{'count_context'}->[-1]->{'locations'}}, $location;
if (!($root->{'extra'} and $root->{'extra'}->{'index_entry'})) {
- $location->{'bytes'}
- = $self->{'count_context'}->[-1]->{'bytes'};
+ _update_count_context($self);
+ $location->{'bytes'} = $self->{'count_context'}->[-1]->{'bytes'};
$location->{'root'} = $root;
} else {
$location->{'index_entry'} = $root;
@@ -770,12 +787,16 @@
my $text = shift;
#$self->_add_lines_count($container->end_line_count());
- $self->{'count_context'}->[-1]->{'lines'} += $container->end_line_count();
+ $self->{'count_context'}->[-1]->{'lines'} += $container->{'end_line_count'};
#$self->_add_text_count($text);
- $self->{'count_context'}->[-1]->{'bytes'} +=
- Texinfo::Common::count_bytes($self, $text,
- $self->{'output_perl_encoding'});
+ #$self->{'count_context'}->[-1]->{'bytes'} +=
+ # Texinfo::Common::count_bytes($self, $text,
+ # $self->{'output_perl_encoding'});
+ if (!defined $self->{'count_context'}->[-1]->{'pending_text'}) {
+ $self->{'count_context'}->[-1]->{'pending_text'} = '';
+ }
+ $self->{'count_context'}->[-1]->{'pending_text'} .= $text;
return $text;
}
@@ -783,6 +804,7 @@
{
my $self = shift;
my $locations = shift;
+ _update_count_context($self);
foreach my $location (@$locations) {
$location->{'bytes'} += $self->{'count_context'}->[-1]->{'bytes'}
if (defined($location->{'bytes'}));
@@ -1044,6 +1066,7 @@
my $max = shift;
my $align = shift;
+ _update_count_context($self);
my $counts = pop @{$self->{'count_context'}};
my $bytes_count;
($result, $bytes_count) = $self->_align_lines($result, $max,
@@ -1169,6 +1192,7 @@
push @{$self->{'count_context'}}, {'lines' => 0, 'bytes' => 0};
$self->{'node_lines_text'}->{$node}->{'text'}
= _normalize_top_node($self->convert_line($node_text));
+ _update_count_context($self);
my $end_context = pop @{$self->{'count_context'}};
$self->{'node_lines_text'}->{$node}->{'count'}
= $end_context->{'bytes'};
@@ -1318,6 +1342,7 @@
my $node_text = $self->gdt('(outside of any node)');
$self->{'outside_of_any_node_text'}->{'text'}
= $self->convert_line($node_text);
+ _update_count_context($self);
my $end_context = pop @{$self->{'count_context'}};
$self->{'outside_of_any_node_text'}->{'count'}
= $end_context->{'bytes'};
@@ -3281,6 +3306,7 @@
pop @{$self->{'format_context'}};
pop @{$self->{'text_element_context'}};
push @{$self->{'format_context'}->[-1]->{'row'}}, $result;
+ _update_count_context($self);
my $cell_counts = pop @{$self->{'count_context'}};
push @{$self->{'format_context'}->[-1]->{'row_counts'}}, $cell_counts;
$result = '';
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [6255] Plaintext.pm faster byte counting,
Gavin D. Smith <=