]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: stop chomping off whitespace at ends of messages
authorEric Wong <e@80x24.org>
Sat, 24 Dec 2016 11:52:42 +0000 (11:52 +0000)
committerEric Wong <e@80x24.org>
Sat, 24 Dec 2016 19:41:00 +0000 (19:41 +0000)
This allows a 3-4% speedup in $MESSAGE_ID/T/ page generation
speed for a 368+ message thread.  It also more faithfully
preserves the message as intended; even if the it makes the
sender look like a space-wasting slob :P

lib/PublicInbox/View.pm

index cf40b55572a3ec71e6a6154bd30768d98479126e..97a8bcbc50719a2691b2297ceee8f9e7cbad4105 100644 (file)
@@ -490,15 +490,13 @@ sub add_text_body {
                }
        }
 
-       my $end = "\n";
-       if (@quot) {
-               $end = '';
+       if (@quot) { # ugh, top posted
                flush_quote(\$s, $l, \@quot);
+       } elsif ($s =~ /\n\z/s) { # common, last line ends with a newline
+               $s;
+       } else { # some editors don't do newlines...
+               $s .= "\n";
        }
-       $s =~ s/[ \t]+$//sgm; # kill per-line trailing whitespace
-       $s =~ s/\A\n+//s; # kill leading blank lines
-       $s =~ s/\s+\z//s; # kill all trailing spaces
-       $s .= $end;
 }
 
 sub _msg_html_prepare {