Re: [PATCH v2 00/10] send-email: various optimizations to speed up by >2x
- From
Jeff King <peff@peff.net>
- Date
- May 21, 2021, 09:37 UTC
- Message-ID
- <YKd/QkWJtmeUJE8T@coredump.intra.peff.net>
- In-Reply-To
- <8735ugphge.fsf@evledraar.gmail.com>
On Fri, May 21, 2021 at 11:24:00AM +0200, Ævar Arnfjörð Bjarmason wrote:
Show 22 quoted lines
> > Using a non-flattened structure would have prevented this (we'd sensibly
> > get undef when trying to access the missing second element of the
> > array). But I do agree the flattened structure is more perl-ish.
> > Probably you'd want to insert an explicit "undef" into the list. The
> > most perl-ish I could come up with is:
> >
> > my (@kv) = map { my ($k, $v) = split /\n/, $_, 2;
> > ($k, $v)
> > } split /\0/, $data;
> >
> > I notice that $known_keys then becomes a non-flat representation. You'd
> > either want to turn that back into a zero-length array there, or store
> > the "undef" and handle it appropriately (it can be a synonym for "true",
> > though that is just an optimization at this point).
> >
> > -Peff
>
> Ah yes, that's indeed a bug. I'd forgetten about the empty value case.
>
> For what it's worth you can slightly golf that as (split /\n/, $_,
> 2)[0,1], but I think in this case your version is better than that, it's
> more obvious what we're trying to do in always returning the $v.Heh. Thanks, I almost invited you to golf it because I was curious if we could continue to do it in one line. I see I didn't need to ask. :)
Yours is clever and I'm glad to be enlightened, but I agree the two-liner is probably more obvious (perhaps even a comment like "bool-only values omit the newline and become undef" is worth it).
-Peff