From: Eric Wong Date: Mon, 24 Jun 2019 02:52:05 +0000 (+0000) Subject: AddTimer: avoid clock_gettime for the '0' case X-Git-Tag: v1.2.0~156^2~55 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=2f9aea4ecb6208955144e8a2290d747a4ff9c966;p=public-inbox.git AddTimer: avoid clock_gettime for the '0' case 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). --- diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index e7db2034..ed04feb5 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -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;