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=-3.9 required=3.0 tests=ALL_TRUSTED,AWL,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 01BF11F885 for ; Sat, 11 Jan 2020 22:35:04 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/9] config: do not slurp entire cgitrc at once Date: Sat, 11 Jan 2020 22:34:55 +0000 Message-Id: <20200111223503.24473-2-e@yhbt.net> In-Reply-To: <20200111223503.24473-1-e@yhbt.net> References: <20200111223503.24473-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: cgitrc files can have hundreds or thousands of lines in them and slurping them into memory is a waste. "while (<$fh>)" only reads one line at a time, whereas "for (<$fh>)" reads the entire contents of the file into a temporary array. --- lib/PublicInbox/Config.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index 56d146c2..1ba1225e 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -249,7 +249,7 @@ sub scan_projects_coderepo ($$$) { warn "failed to open cgit projectlist=$list: $!\n"; return; }; - foreach (<$fh>) { + while (<$fh>) { chomp; scan_path_coderepo($self, $path, "$path/$_"); } @@ -274,7 +274,7 @@ sub parse_cgitrc { # FIXME: this doesn't support macro expansion via $VARS, yet my $repo; - foreach (<$fh>) { + while (<$fh>) { chomp; if (m!\Arepo\.url=(.+?)/*\z!) { my $nick = $1;