diff options
author | Eric Wong <e@80x24.org> | 2023-01-29 10:30:41 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-01-30 06:42:31 +0000 |
commit | e6aa13bccb7ea5d5b3246b3a944621515905e360 (patch) | |
tree | 822309b8cc2ac85ba50acd33deebb03891b0844b /lib/PublicInbox/ContentHash.pm | |
parent | 9eb8baf199cd148b7ebf8e6e130fb832f4e1ef00 (diff) | |
download | public-inbox-e6aa13bccb7ea5d5b3246b3a944621515905e360.tar.gz |
On my x86-64 machine, OpenSSL SHA-256 is nearly twice as fast as the Digest::SHA implementation from Perl, most likely due to an optimized assembly implementation. SHA-1 is a few percent faster, too.
Diffstat (limited to 'lib/PublicInbox/ContentHash.pm')
-rw-r--r-- | lib/PublicInbox/ContentHash.pm | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/PublicInbox/ContentHash.pm b/lib/PublicInbox/ContentHash.pm index 1afbb413..d3ff146a 100644 --- a/lib/PublicInbox/ContentHash.pm +++ b/lib/PublicInbox/ContentHash.pm @@ -15,7 +15,8 @@ use PublicInbox::MID qw(mids references); use PublicInbox::MsgIter; # not sure if less-widely supported hash families are worth bothering with -use Digest::SHA; +use PublicInbox::SHA; # faster, but no ->clone +use Digest::SHA; # we still need this for ->clone sub digest_addr ($$$) { my ($dig, $h, $v) = @_; @@ -93,15 +94,15 @@ sub content_digest ($;$) { } sub content_hash ($) { - content_digest($_[0])->digest; + content_digest($_[0], PublicInbox::SHA->new(256))->digest; } +# don't clone the result of this sub git_sha ($$) { my ($n, $eml) = @_; - my $dig = Digest::SHA->new($n); + my $dig = PublicInbox::SHA->new($n); my $bref = ref($eml) eq 'SCALAR' ? $eml : \($eml->as_string); - $dig->add('blob '.length($$bref)."\0"); - $dig->add($$bref); + $dig->add('blob '.length($$bref)."\0", $$bref); $dig; } |