On Fri, Aug 14, 2026 at 04:42:32PM +0200, Patrice Dumas wrote: > The second is about easing the implementation. We convert to UTF-8 upon > reading and do everything in this encoding, in particular determining > line width for cutting lines, or centering or flushing right. In Info > output, however, we also need to track the bytes count in the output > encoding to fill the Info tag tables that allows to find anchors and > nodes in Info file. Therefore, we do the output in two phases, first > conversion in UTF-8 and then encoding to determine bytes counts. In > some cases it is not easy to do it in two phases, we need to convert > back already encoded strings to UTF-8 to do the counting. Outputting > in UTF-8 only would remove > * the need to do two phases > * the need to convert back
I don't know if it helps but I have the commit below sitting on my "git stash" list (since 2024-01-24!). At least at that time, I was looking at eliminating the _decode function in Plaintext.pm (which reverses the encoding_ - so there is a chance this is possible. As far as I remember it was possible and I didn't make the change because there was a very slight performance impact - that said, I don't remember the details. I'm not expecting anybody to make sense of my old, incomplete patch, just posting it to demonstrate that it was a real possibility that could be explored further. commit e7a667239560e25fbfdedafdc453549c7527cadb Merge: 3c25f2b54d d6c24486a0 Author: Gavin Smith <[email protected]> Date: 2024-01-24 18:05:23 +0000 WIP on master: 3c25f2b54d * tp/Texinfo/Convert/Plaintext.pm (process_printindex) <(outside of any node>: Call convert_line_new_context with encoding disabled. diff --cc tp/Texinfo/Convert/Info.pm index 04fff3f421,04fff3f421..7227d846fc --- a/tp/Texinfo/Convert/Info.pm +++ b/tp/Texinfo/Convert/Info.pm @@@ -316,6 -316,6 +316,7 @@@ sub output($$ $prefix = 'Ref'; } my ($label_text, undef) = $self->node_name($label->{'root'}); ++ my $label_text_encoded = $self->_stream_encode($label_text); if ($seen_anchors{$label_text}) { $self->plaintext_line_error($self, @@@ -329,7 -329,7 +330,7 @@@ $seen_anchors{$label_text} = 1; } -- $tag_text .= "$prefix: $label_text\x{7F}$label->{'bytes'}\n"; ++ $tag_text .= "$prefix: $label_text_encoded\x{7F}$label->{'bytes'}\n"; } $tag_text .= "\x{1F}\nEnd Tag Table\n"; @@@ -529,8 -529,8 +530,8 @@@ sub format_node($$ if ($node_text =~ /,/) { if ($self->{'info_special_chars_warning'}) { $self->plaintext_line_warn($self, sprintf(__( -- "\@node name should not contain `,': %s"), -- $self->_decode($node_text)), $node->{'source_info'}); ++ "\@node name should not contain `,': %s"), $node_text), ++ $node->{'source_info'}); } if ($self->{'info_special_chars_quote'}) { $pre_quote = "\x{7f}"; diff --cc tp/Texinfo/Convert/Plaintext.pm index 2c7217e715,2c7217e715..544339728a --- a/tp/Texinfo/Convert/Plaintext.pm +++ b/tp/Texinfo/Convert/Plaintext.pm @@@ -1001,19 -1001,19 +1001,6 @@@ sub _stream_byte_count($ return $count_context->{'bytes'}; } --# Used occasionally for already encoded output --sub _decode($$) --{ -- my ($self, $encoded) = @_; -- -- if (!$self->{'encoding_object'}) { -- return $encoded; # probably wrong -- } else { -- my $decoded = $self->{'encoding_object'}->decode($encoded); -- return $decoded; -- } --} -- # Occassionally, we need to find the width of a string after it has # already been encoded. Use of this should be minimised for performance. sub _string_width_encoded($$) @@@ -1466,7 -1466,7 +1453,7 @@@ sub node_name($$ 'contents' => [$label_element]}; my ($result, $width) = $self->convert_line_new_context($node_text, {'suppress_styles' => 1, -- 'no_added_eol' => 1,}); ++ 'no_added_eol' => 1,}, 1); $self->{'node_names_text'}->{$node} = {'text' => _normalize_top_node($result), 'width' => $width }; @@@ -1705,7 -1705,7 +1692,7 @@@ sub process_printindex($$;$ $node_name = $pre_quote . $node_name . $post_quote; } } -- _stream_output_encoded($self, $node_name); ++ _stream_output($self, $node_name); $line_width += $width; } _stream_output($self, '.');
