Commit c53259a
committed
perf(filedir_xspec): avoid double negation !(!(...)) in extglob
Due to the Bash implementatin of negation matching, nested negations
becomes extremely slow for a long filename. "!(!(...))" is
interchangeable with "@(...)".
The actual overhead caused by "!(!(...))" largely depends on the
pattern specified to "...", but it is hard to predict. For example,
"+(0)+(?).txt" or "+(+(0)).txt" may cause a large delay. Although
those specific patterns are not used in bash-completion, but it is not
predictable whether other patterns in bash-completion cause the same
problem. It is recommended to avoid "!(!(...))" in general.
Examples:
$ time bash -O extglob -c 'echo !(!(+(+(0)).txt))'
00000000000000000000.txt
real 0m4.537s
$ time bash -O extglob -c 'echo !(!(+(0)+(?).txt))'
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.txt
real 0m0.991s1 parent f40a0ca commit c53259a
1 file changed
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3264 | 3264 | | |
3265 | 3265 | | |
3266 | 3266 | | |
3267 | | - | |
3268 | 3267 | | |
3269 | 3268 | | |
3270 | | - | |
| 3269 | + | |
| 3270 | + | |
| 3271 | + | |
3271 | 3272 | | |
3272 | | - | |
3273 | 3273 | | |
3274 | | - | |
| 3274 | + | |
3275 | 3275 | | |
3276 | 3276 | | |
3277 | 3277 | | |
| |||
0 commit comments