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, T_SCC_BODY_TEXT_LINE 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 CEEE01F66E for ; Mon, 18 Apr 2022 09:50:05 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 4/4] syscall: golf + more idiomatic buffer initialization Date: Mon, 18 Apr 2022 09:50:04 +0000 Message-Id: <20220418095004.466-5-e@80x24.org> In-Reply-To: <20220418095004.466-1-e@80x24.org> References: <20220418095004.466-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While `vec' is useful for user-supplied buffers to avoid excess memory traffic, but provides no benefit when we need to allocate our own buffers as we do in nodatacow_fh, since Perl can't elide memset(ptr, 0, len). So just use the idiomatic `"\0" x $LEN' here. --- lib/PublicInbox/Syscall.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm index cc282f9f..22b779ad 100644 --- a/lib/PublicInbox/Syscall.pm +++ b/lib/PublicInbox/Syscall.pm @@ -390,12 +390,10 @@ sub rename_noreplace ($$) { } } -sub nodatacow_fh { - return if !defined($SYS_fstatfs); - my $buf = ''; - vec($buf, 120 * 8 - 1, 1) = 0; +sub nodatacow_fh ($) { my ($fh) = @_; - syscall($SYS_fstatfs, fileno($fh), $buf) == 0 or + my $buf = "\0" x 120; + syscall($SYS_fstatfs // return, fileno($fh), $buf) == 0 or return warn("fstatfs: $!\n"); my $f_type = unpack('l!', $buf); # statfs.f_type is a signed word return if $f_type != 0x9123683E; # BTRFS_SUPER_MAGIC