]> Sergey Matveev's repositories - public-inbox.git/commitdiff
AddTimer: avoid clock_gettime for the '0' case
authorEric Wong <e@80x24.org>
Mon, 24 Jun 2019 02:52:05 +0000 (02:52 +0000)
committerEric Wong <e@80x24.org>
Mon, 24 Jun 2019 05:26:25 +0000 (05:26 +0000)
We rely on immediate timers often, so we can avoid the overhead
of an extra subroutine call to retrieve the monotonic time (and
a sometimes-system call on some platforms).

lib/PublicInbox/DS.pm

index e7db2034c868a78a64bbaf18d3f23e25a9f0040b..ed04feb5c9e0d699feb0a4b05252aa29b8faa1aa 100644 (file)
@@ -113,8 +113,13 @@ Returns a timer object which you can call C<< $timer->cancel >> on if you need t
 
 =cut
 sub AddTimer {
-    my $class = shift;
-    my ($secs, $coderef) = @_;
+    my ($class, $secs, $coderef) = @_;
+
+    if (!$secs) {
+        my $timer = bless([0, $coderef], 'PublicInbox::DS::Timer');
+        unshift(@Timers, $timer);
+        return $timer;
+    }
 
     my $fire_time = now() + $secs;