completion: improve ls-files filter performance
commit78a2d2123103f4524bfce30511e0a8b2d27d3502
authorClemens Buchacher <drizzd@gmx.net>
Wed, 4 Apr 2018 07:46:58 +0000 (4 09:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 10 Apr 2018 07:00:53 +0000 (10 16:00 +0900)
treeccd046b72f49c85bb3c6a19290fdeee0bd07fd98
parent468165c1d8a442994a825f3684528361727cd8c0
completion: improve ls-files filter performance

From the output of ls-files, we remove all but the leftmost path
component and then we eliminate duplicates. We do this in a while loop,
which is a performance bottleneck when the number of iterations is large
(e.g. for 60000 files in linux.git).

$ COMP_WORDS=(git status -- ar) COMP_CWORD=3; time _git

real    0m11.876s
user    0m4.685s
sys     0m6.808s

Replacing the loop with the cut command improves performance
significantly:

$ COMP_WORDS=(git status -- ar) COMP_CWORD=3; time _git

real    0m1.372s
user    0m0.263s
sys     0m0.167s

The measurements were done with Msys2 bash, which is used by Git for
Windows.

When filtering the ls-files output we take care not to touch absolute
paths. This is redundant, because ls-files will never output absolute
paths. Remove the unnecessary operations.

The issue was reported here:
https://github.com/git-for-windows/git/issues/1533

Signed-off-by: Clemens Buchacher <drizzd@gmx.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash