From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 965041F4BA for ; Mon, 24 Jun 2019 02:52:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 04/57] AddTimer: avoid clock_gettime for the '0' case Date: Mon, 24 Jun 2019 02:52:05 +0000 Message-Id: <20190624025258.25592-5-e@80x24.org> In-Reply-To: <20190624025258.25592-1-e@80x24.org> References: <20190624025258.25592-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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; -- EW