fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-11-30 04:05 pm

[dw-free] regexp cleanup

[commit: http://hg.dwscoalition.org/dw-free/rev/b78af312d67f]

http://bugs.dwscoalition.org/show_bug.cgi?id=2792

Efficiency/code cleanup. Refactor common code into a new function; use $1
instead of $& for efficiency. (match only one group)

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/Talk.pm
  • htdocs/talkpost.bml
  • htdocs/talkread.bml
--------------------------------------------------------------------------------
diff -r 384b3e3c85c0 -r b78af312d67f cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm	Tue Nov 30 23:54:39 2010 +0800
+++ b/cgi-bin/LJ/Talk.pm	Wed Dec 01 00:05:40 2010 +0800
@@ -2394,6 +2394,13 @@ sub treat_as_anon {
     return LJ::isu( $u ) ? ! $u->trusts_or_has_member( $pu ) : 1;
 }
 
+sub format_eventtime {
+    my ( $etime, $u ) = @_;
+    $etime ||= '';
+    $etime =~ s!(\d{4}-\d{2}-\d{2})!LJ::date_to_view_links( $u, $1 )!e;
+    return "<br /><span class='time'>@ $etime</span>";
+}
+
 package LJ::Talk::Post;
 
 use Text::Wrap;
diff -r 384b3e3c85c0 -r b78af312d67f htdocs/talkpost.bml
--- a/htdocs/talkpost.bml	Tue Nov 30 23:54:39 2010 +0800
+++ b/htdocs/talkpost.bml	Wed Dec 01 00:05:40 2010 +0800
@@ -263,9 +263,7 @@ body<=
     }
 
     unless ($init->{'replyto'}) {
-        my $etime = $item->{'eventtime'};
-        $etime =~ s!(\d\d\d\d)-(\d\d)-(\d\d)!LJ::date_to_view_links($u, $&)!e;
-        $ret .= "<br /><span class='time'>@ $etime</span>";
+        $ret .= LJ::Talk::format_eventtime( $item->{eventtime}, $u );
     }
 
     $ret .= "</td></tr></table>";
diff -r 384b3e3c85c0 -r b78af312d67f htdocs/talkread.bml
--- a/htdocs/talkread.bml	Tue Nov 30 23:54:39 2010 +0800
+++ b/htdocs/talkread.bml	Wed Dec 01 00:05:40 2010 +0800
@@ -274,8 +274,7 @@ body<=
     $etime = LJ::S2::DateTime_unix( $etime );
     $etime = S2::Builtin::LJ::Date__date_format( $s2_ctx, $etime, "iso" ) .
             " " . S2::Builtin::LJ::DateTime__time_format( $s2_ctx, $etime, $fmt_time_short );
-    $etime =~ s!(\d\d\d\d)-(\d\d)-(\d\d)!LJ::date_to_view_links($u, $&)!e;
-    $ret .= "<br /><span class='time'>@ $etime</span>";
+    $ret .= LJ::Talk::format_eventtime( $etime, $u );
     $ret .= "</td></tr></table>";
 
     ## standout bar
--------------------------------------------------------------------------------