about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-04-05 07:53:49 +0000
committerEric Wong <e@yhbt.net>2020-04-05 22:06:23 +0000
commitb9cc3985078111b1fb38de920fd3b7afe3eec542 (patch)
treea469c00f37583d31857a011e3828b7ff430032c3
parent1e5d704f1234ded472b800e42bedb5579780296e (diff)
downloadpublic-inbox-b9cc3985078111b1fb38de920fd3b7afe3eec542.tar.gz
The stat() array is a whopping 480 bytes (on x86-64, Perl 5.28),
while the new packed representation of two 64-bit doubles as a
scalar is "only" 56 bytes.  This can add up when there's many
inboxes.  Just use a string comparison on the packed
representation.

Some 32-bit Perl builds (IIRC OpenBSD) lack quad support, so
doubles were chosen for pack() portability.
-rw-r--r--lib/PublicInbox/Git.pm13
1 files changed, 6 insertions, 7 deletions
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 9c96b3f0..8410b2fc 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -55,10 +55,8 @@ sub git_quote ($) {
 
 sub new {
         my ($class, $git_dir) = @_;
-        my @st;
-        $st[7] = $st[10] = 0;
         # may contain {-tmp} field for File::Temp::Dir
-        bless { git_dir => $git_dir, st => \@st, -git_path => {} }, $class
+        bless { git_dir => $git_dir, alt_st => '', -git_path => {} }, $class
 }
 
 sub git_path ($$) {
@@ -79,10 +77,11 @@ sub alternates_changed {
         my ($self) = @_;
         my $alt = git_path($self, 'objects/info/alternates');
         my @st = stat($alt) or return 0;
-        my $old_st = $self->{st};
-        # 10 - ctime, 7 - size
-        return 0 if ($st[10] == $old_st->[10] && $st[7] == $old_st->[7]);
-        $self->{st} = \@st;
+
+        # can't rely on 'q' on some 32-bit builds, but `d' works
+        my $st = pack('dd', $st[10], $st[7]); # 10: ctime, 7: size
+        return 0 if $self->{alt_st} eq $st;
+        $self->{alt_st} = $st; # always a true value
 }
 
 sub last_check_err {