ref-filter: resolve HEAD when parsing %(HEAD) atom
commit613a0e52ea11c4496e3e154de192486a18eac2e4
authorJeff King <peff@peff.net>
Fri, 19 May 2017 06:12:12 +0000 (19 02:12 -0400)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 May 2017 09:18:45 +0000 (20 18:18 +0900)
treeba35570dbd632ef85686276574abf025a0487296
parentac5bbc02b8c3781d517f1414655270b3fa38b028
ref-filter: resolve HEAD when parsing %(HEAD) atom

If the user asks to display (or sort by) the %(HEAD) atom,
ref-filter has to compare each refname to the value of HEAD.
We do so by resolving HEAD fresh when calling populate_value()
on each ref. If there are a large number of refs, this can
have a measurable impact on runtime.

Instead, let's resolve HEAD once when we realize we need the
%(HEAD) atom, allowing us to do a simple string comparison
for each ref. On a repository with 3000 branches (high, but
an actual example found in the wild) this drops the
best-of-five time to run "git branch >/dev/null" from 59ms
to 48ms (~20% savings).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ref-filter.c