git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 5/7] completion: fix expansion issues in __gitcomp_nl()

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Nov 17, 2012, 19:08 UTC
Message-ID
<CAMP44s2YOshWkM9n2XxxLw79=-VF8U3Q4ta1D1zgHqWH30zOmw@mail.gmail.com>
In-Reply-To
<20121117141422.GI12052@goldbirke>
On Sat, Nov 17, 2012 at 3:14 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:
Show 44 quoted lines
> On Sat, Nov 17, 2012 at 12:50:39PM +0100, Felipe Contreras wrote:
>> On Sat, Nov 17, 2012 at 12:05 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:
>>
>> >  __gitcomp_nl ()
>> >  {
>> >         local IFS=$'\n'
>> > -       COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
>> > +       COMPREPLY=($(awk -v pfx="${2-}" -v sfx="${4- }" -v cur="${3-$cur}" '
>> > +               BEGIN {
>> > +                       FS="\n";
>> > +                       len=length(cur);
>> > +               }
>> > +               {
>> > +                       if (cur == substr($1, 1, len))
>> > +                               print pfx$1sfx;
>> > +               }' <<< "$1" ))
>> >  }
>>
>> Does this really perform better than my alternative?
>>
>> +       for x in $1; do
>> +               if [[ "$x" = "$3"* ]]; then
>> +                       COMPREPLY+=("$2$x$4")
>> +               fi
>> +       done
>
> It does:
>
>   My version:
>
>     $ refs="$(for i in {0..9999} ; do echo branch$i ; done)"
>     $ time __gitcomp_nl "$refs"
>
>     real    0m0.109s
>     user    0m0.096s
>     sys     0m0.012s
>
>   Yours:
>
>     $ time __gitcomp_nl "$refs"
>
>     real    0m0.321s
>     user    0m0.312s
>     sys     0m0.008s
Yeah, for 10000 refs, which is not the common case:

== 1 == SZEDER: real 0m0.007s user 0m0.003s sys 0m0.000s felipec: real 0m0.000s user 0m0.000s sys 0m0.000s == 10 == SZEDER: real 0m0.004s user 0m0.003s sys 0m0.001s felipec: real 0m0.000s user 0m0.000s sys 0m0.000s == 100 == SZEDER: real 0m0.005s user 0m0.002s sys 0m0.002s felipec: real 0m0.002s user 0m0.002s sys 0m0.000s == 1000 == SZEDER: real 0m0.010s user 0m0.008s sys 0m0.001s felipec: real 0m0.018s user 0m0.017s sys 0m0.001s == 10000 == SZEDER: real 0m0.062s user 0m0.060s sys 0m0.003s felipec: real 0m0.175s user 0m0.174s sys 0m0.000s == 100000 == SZEDER: real 0m0.595s user 0m0.593s sys 0m0.021s felipec: real 0m1.848s user 0m1.843s sys 0m0.003s == 1000000 == SZEDER: real 0m6.258s user 0m6.241s sys 0m0.215s felipec: real 0m18.191s user 0m18.115s sys 0m0.045s

-- 
Felipe Contreras
Previous: SZEDER GáborNext: Felipe Contreras
Message 19 of 26 in “completion: fix expansion issues with compgen”
  1. 0/7 completion: fix expansion issues with compgenSZEDER Gábor, Nov 17, 2012
  2. 1/7 completion: make the 'basic' test more tester-friendlySZEDER Gábor, Nov 17, 2012
  3. Jonathan NiederNov 17, 2012
  4. Felipe ContrerasNov 18, 2012
  5. Felipe ContrerasNov 18, 2012
  6. 2/7 completion: fix args of run_completion() test helperSZEDER Gábor, Nov 17, 2012
  7. Jonathan NiederNov 17, 2012
  8. Felipe ContrerasNov 18, 2012
  9. 3/7 completion: add tests for the __gitcomp_nl() completion helper functionSZEDER Gábor, Nov 17, 2012
  10. Jonathan NiederNov 17, 2012
  11. Felipe ContrerasNov 18, 2012
  12. 4/7 completion: add tests for invalid variable name among completion wordsSZEDER Gábor, Nov 17, 2012
  13. Jonathan NiederNov 17, 2012
  14. Felipe ContrerasNov 18, 2012
  15. Felipe ContrerasNov 18, 2012
  16. 5/7 completion: fix expansion issues in __gitcomp_nl()SZEDER Gábor, Nov 17, 2012
  17. Felipe ContrerasNov 17, 2012
  18. SZEDER GáborNov 17, 2012
  19. Felipe ContrerasNov 17, 2012
  20. Felipe ContrerasNov 17, 2012
  21. Felipe ContrerasNov 18, 2012
  22. Felipe ContrerasNov 18, 2012
  23. 6/7 completion: fix expansion issue in __gitcomp()SZEDER Gábor, Nov 17, 2012
  24. Felipe ContrerasNov 17, 2012
  25. SZEDER GáborNov 17, 2012
  26. 7/7 completion: remove the now unused __gitcomp_1() internal helper functionSZEDER Gábor, Nov 17, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.