summaryrefslogtreecommitdiff
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-05-28 09:23:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-05-28 09:38:07 (GMT)
commitfef381e6dcbc328c4ccabaf4e8d4cdf19d1aba00 (patch)
tree9632ebec360b77af28e9bcf33d3e585c97ccea71 /git-send-email.perl
parent9264d29bf6da9e1789d71807dd72bbd4fb447887 (diff)
downloadgit-fef381e6dcbc328c4ccabaf4e8d4cdf19d1aba00.zip
git-fef381e6dcbc328c4ccabaf4e8d4cdf19d1aba00.tar.gz
git-fef381e6dcbc328c4ccabaf4e8d4cdf19d1aba00.tar.bz2
send-email: lazily shell out to "git var"
Optimize git-send-email by only shelling out to "git var" if we need to. This is easily done by re-inventing our own small version of perl's Memoize module. I suppose I could just use Memoize itself, but in a subsequent patch I'll be micro-optimizing send-email's use of dependencies. Using Memoize is a measly extra 5-10 milliseconds, but as we'll see that'll end up mattering for us in the end. This brings the runtime of a plain "send-email" from around ~160-170ms to ~140m-150ms. The runtime of the tests is around the same, or around ~20s. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl20
1 files changed, 15 insertions, 5 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index de62cbf..38408ec 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -588,8 +588,18 @@ if (0) {
}
my ($repoauthor, $repocommitter);
-($repoauthor) = Git::ident_person(@repo, 'author');
-($repocommitter) = Git::ident_person(@repo, 'committer');
+{
+ my %cache;
+ my ($author, $committer);
+ my $common = sub {
+ my ($what) = @_;
+ return $cache{$what} if exists $cache{$what};
+ ($cache{$what}) = Git::ident_person(@repo, $what);
+ return $cache{$what};
+ };
+ $repoauthor = sub { $common->('author') };
+ $repocommitter = sub { $common->('committer') };
+}
sub parse_address_line {
return map { $_->format } Mail::Address->parse($_[0]);
@@ -777,7 +787,7 @@ if ($compose) {
or die sprintf(__("Failed to open for writing %s: %s"), $compose_filename, $!);
- my $tpl_sender = $sender || $repoauthor || $repocommitter || '';
+ my $tpl_sender = $sender || $repoauthor->() || $repocommitter->() || '';
my $tpl_subject = $initial_subject || '';
my $tpl_in_reply_to = $initial_in_reply_to || '';
my $tpl_reply_to = $reply_to || '';
@@ -983,7 +993,7 @@ if (defined $sender) {
$sender =~ s/^\s+|\s+$//g;
($sender) = expand_aliases($sender);
} else {
- $sender = $repoauthor || $repocommitter || '';
+ $sender = $repoauthor->() || $repocommitter->() || '';
}
# $sender could be an already sanitized address
@@ -1132,7 +1142,7 @@ sub make_message_id {
$uniq = "$message_id_stamp-$message_id_serial";
my $du_part;
- for ($sender, $repocommitter, $repoauthor) {
+ for ($sender, $repocommitter->(), $repoauthor->()) {
$du_part = extract_valid_address(sanitize_address($_));
last if (defined $du_part and $du_part ne '');
}