[Rt-commit] rt branch, 4.2/date-pm-micro-optimizations, created. rt-4.0.6-493-g220675a

Ruslan Zakirov ruz at bestpractical.com
Sun Aug 26 16:13:16 EDT 2012


The branch, 4.2/date-pm-micro-optimizations has been created
        at  220675a651147d7c35565535f686164130bd259d (commit)

- Log -----------------------------------------------------------------
commit 40340bd026532211caaac2957a4ac00de49fc6ba
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun Aug 26 23:38:35 2012 +0400

    use eq rather than match where possible

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index ed094d0..9a5d73a 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -166,10 +166,12 @@ sub Set {
 
     return $self->Unix(0) unless $args{'Value'} && $args{'Value'} =~ /\S/;
 
-    if ( $args{'Format'} =~ /^unix$/i ) {
+    my $format = lc $args{'Format'};
+
+    if ( $format eq 'unix' ) {
         return $self->Unix( $args{'Value'} );
     }
-    elsif ( $args{'Format'} =~ /^(sql|datemanip|iso)$/i ) {
+    elsif ( $format =~ /^(sql|datemanip|iso)$/ ) {
         $args{'Value'} =~ s!/!-!g;
 
         if (   ( $args{'Value'} =~ /^(\d{4})?(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/ )
@@ -201,7 +203,7 @@ sub Set {
             return $self->Unix(0);
         }
     }
-    elsif ( $args{'Format'} =~ /^unknown$/i ) {
+    elsif ( $format eq 'unknown' ) {
         require Time::ParseDate;
         # the module supports only legacy timezones like PDT or EST...
         # so we parse date as GMT and later apply offset, this only

commit 0f9dc7d89ecd1d96c27e600eb242e4d9b2b44276
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun Aug 26 23:40:02 2012 +0400

    just call ->Unix instead of recursion into ->Set
    
    we do this nearby for other formats

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index 9a5d73a..5eca8fd 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -225,7 +225,7 @@ sub Set {
             "RT::Date used Time::ParseDate to make '$args{'Value'}' $date\n"
         );
 
-        return $self->Set( Format => 'unix', Value => $date);
+        return $self->Unix($date || 0);
     }
     else {
         $RT::Logger->error(

commit fc80613bb0d0d82cc37ebb95b49509c11bba5942
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Sun Aug 26 23:41:43 2012 +0400

    separate elsif branch for one SQL/ISO format
    
    This format we use when fetch from DB. All fields in the string
    are mandatory and it's treated as UTC time.
    
    For this particular and very common case we can do
    faster conversion to unix time. Other elsif branch
    still handles more variants.
    
    Our existing tests dictate that we normalize old dates
    (negative unix time) to zero, as well as, invalid dates.
    I think that we can avoid validation and use timegm_nocheck.

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index 5eca8fd..16e3236 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -171,6 +171,15 @@ sub Set {
     if ( $format eq 'unix' ) {
         return $self->Unix( $args{'Value'} );
     }
+    elsif (
+        ($format eq 'sql' || $format eq 'iso')
+        && $args{'Value'} =~ /^(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/
+    ) {
+        local $@;
+        my $u = eval { Time::Local::timegm($6, $5, $4, $3, $2-1, $1) } || 0;
+        $RT::Logger->warning("Invalid date $args{'Value'}: $@") if $@ && !$u;
+        return $self->Unix( $u > 0 ? $u : 0 );
+    }
     elsif ( $format =~ /^(sql|datemanip|iso)$/ ) {
         $args{'Value'} =~ s!/!-!g;
 

commit b5c4f4498e79940f0a170ea0925d2769c23846ae
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Aug 27 00:06:35 2012 +0400

    rather than map+array assign we can change inplace

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index 16e3236..b6bc336 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -631,7 +631,7 @@ sub DefaultFormat
                             $self->Localtime($args{'Timezone'});
     $wday = $self->GetWeekday($wday);
     $mon = $self->GetMonth($mon);
-    ($mday, $hour, $min, $sec) = map { sprintf "%02d", $_ } ($mday, $hour, $min, $sec);
+    $_ = sprintf "%02d", $_ foreach $mday, $hour, $min, $sec;
 
     if( $args{'Date'} && !$args{'Time'} ) {
         return $self->loc('[_1] [_2] [_3] [_4]',

commit 220675a651147d7c35565535f686164130bd259d
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Mon Aug 27 00:07:28 2012 +0400

    drop a check, code below comes to the same result

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index b6bc336..1a2a501 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -1064,8 +1064,6 @@ sub Timezone {
 
     my $context = lc(shift);
 
-    $context = 'utc' unless $context =~ /^(?:utc|server|user)$/i;
-
     my $tz;
     if( $context eq 'user' ) {
         $tz = $self->CurrentUser->UserObj->Timezone;

-----------------------------------------------------------------------


More information about the Rt-commit mailing list