[Rt-commit] rt branch, 4.2/date-pm-micro-optimizations, created. rt-4.1.6-348-gcfca23a

Ruslan Zakirov ruz at bestpractical.com
Tue Mar 12 18:11:53 EDT 2013


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

- Log -----------------------------------------------------------------
commit 62987671d416f495ff54050688445c377fbe98cc
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 d362197..20e806e 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 92f291a82f5e99d51cabbbb15ceb61c795a1a252
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 20e806e..5eb20ee 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 92c131a6193d637dc8a21ca412deee3f2e42808e
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 5eb20ee..8638000 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 07fda2f5a581e04b69f4c4a8bba67e2685443494
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 8638000..4bc3198 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 cfca23acc14b2c4cc5d644506d1dbe42bc3d4435
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 4bc3198..c9dcb3b 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