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.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF 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 E12921F61D for ; Thu, 4 Aug 2022 08:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1659601024; bh=rKeWOh2Yzp08sv/EXDKXqfSkcjEv4XKVJz6VQytDSrQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qS92UuGd5PhndvTIYNi5goFMmMq68m3yww1EIW6/sIm9lV3ATdaAfj6nUGlbOEa9+ fYAZENnnzbNe/zYTLuuhmHWkB6S5dLPiB3WrEhUPU5n+rr9d4NiAkGpuBjLrPXYo8M 0GJIob+Sx+RJ3XtL/QzCYP5CQn33NOrkycE/iCPA= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 6/7] feed: avoid unnecessary map loop in non-over path Date: Thu, 4 Aug 2022 08:17:02 +0000 Message-Id: <20220804081703.1410595-7-e@80x24.org> In-Reply-To: <20220804081703.1410595-1-e@80x24.org> References: <20220804081703.1410595-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We can bless objects while doing the initial insertion to avoid extra the extra map iteration and temporary array(s). Fewer ops means memory savings for the likely case of ->over users, too. --- lib/PublicInbox/Feed.pm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index b2219dad..ee579f6d 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -1,10 +1,10 @@ -# Copyright (C) 2013-2021 all contributors +# Copyright (C) all contributors # License: AGPL-3.0+ # # Used for generating Atom feeds for web-accessible mailing list archives. package PublicInbox::Feed; use strict; -use warnings; +use v5.10.1; use PublicInbox::View; use PublicInbox::WwwAtomStream; use PublicInbox::Smsg; # this loads w/o Search::Xapian @@ -108,13 +108,13 @@ sub recent_msgs { my $last; my $last_commit; local $/ = "\n"; - my @oids; + my @ret; while (defined(my $line = <$log>)) { if ($line =~ /$addmsg/o) { my $add = $1; next if $deleted{$add}; # optimization-only - push @oids, $add; - if (scalar(@oids) >= $max) { + push(@ret, bless { blob => $add }, 'PublicInbox::Smsg'); + if (scalar(@ret) >= $max) { $last = 1; last; } @@ -136,8 +136,7 @@ sub recent_msgs { $last_commit and $ctx->{next_page} = qq[] . 'next (older)'; - - [ map { bless {blob => $_ }, 'PublicInbox::Smsg' } @oids ]; + \@ret; } 1;