user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] view: avoid deduping a single word in subject skeletons
@ 2017-12-21  1:00  7% Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2017-12-21  1:00 UTC (permalink / raw)
  To: meta

It is usually pointless to replace a single word with a '"' character.
---
 lib/PublicInbox/View.pm | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 41f1321..81e83d9 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -755,6 +755,25 @@ sub _msg_date {
 
 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
 
+sub dedupe_subject {
+	my ($prev_subj, $subj, $val) = @_;
+
+	my $omit = ''; # '"' denotes identical text omitted
+	my (@prev_pop, @curr_pop);
+	while (@$prev_subj && @$subj && $subj->[-1] eq $prev_subj->[-1]) {
+		push(@prev_pop, pop(@$prev_subj));
+		push(@curr_pop, pop(@$subj));
+		$omit ||= $val;
+	}
+	pop @$subj if @$subj && $subj->[-1] =~ /^re:\s*/i;
+	if (scalar(@curr_pop) == 1) {
+		$omit = '';
+		push @$prev_subj, @prev_pop;
+		push @$subj, @curr_pop;
+	}
+	$omit;
+}
+
 sub skel_dump {
 	my ($ctx, $level, $node) = @_;
 	my $smsg = $node->{smsg} or return _skel_ghost($ctx, $level, $node);
@@ -798,13 +817,7 @@ sub skel_dump {
 	# so we do not show redundant text at the end.
 	my $prev_subj = $ctx->{prev_subj} || [];
 	$ctx->{prev_subj} = [ @subj ];
-	my $omit = ''; # '"' denotes identical text omitted
-	while (@$prev_subj && @subj && $subj[-1] eq $prev_subj->[-1]) {
-		pop @$prev_subj;
-		pop @subj;
-		$omit ||= '" ';
-	}
-	pop @subj if @subj && $subj[-1] =~ /^re:\s*/i;
+	my $omit = dedupe_subject($prev_subj, \@subj, '" ');
 	my $end;
 	if (@subj) {
 		my $subj = join(' ', @subj);
@@ -944,14 +957,7 @@ sub dump_topics {
 			$mid = delete $seen->{$subj};
 			my @subj = split(/ /, $srch->subject_normalized($subj));
 			my @next_prev = @subj; # full copy
-			my $omit = ''; # '"' denotes identical text omitted
-			while (@$prev_subj && @subj &&
-					$subj[-1] eq $prev_subj->[-1]) {
-				pop @$prev_subj;
-				pop @subj;
-				$omit ||= ' "';
-			}
-			pop @subj if @subj && $subj[-1] =~ /^re:\s*/i;
+			my $omit = dedupe_subject($prev_subj, \@subj, ' "');
 			$prev_subj = \@next_prev;
 			$subj = ascii_html(join(' ', @subj));
 			obfuscate_addrs($obfs_ibx, $subj) if $obfs_ibx;
-- 
EW


^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2017-12-21  1:00  7% [PATCH] view: avoid deduping a single word in subject skeletons Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).