]> git.ipfire.org Git - thirdparty/vim.git/commit
patch 9.1.1556: string handling in cmdexpand.c can be improved v9.1.1556
authorJohn Marriott <basilisk@internode.on.net>
Wed, 16 Jul 2025 18:09:13 +0000 (20:09 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 16 Jul 2025 18:09:13 +0000 (20:09 +0200)
commit393d398247440f7045acf703cd179ad0da148318
treeb0fcf34ec26826e733fcab1d87815caff032e8e1
parent78b10eab6c4ce4eb6556202e940a1980a472498b
patch 9.1.1556: string handling in cmdexpand.c can be improved

Problem:  string handling in cmdexpand.c can be improved
Solution: Improve string manipulation in cmdexpand.c (John Marriott).

This PR does the following:

In cmdline_fuzzy_completion_supported():
- replace the series of if tests with a switch

In expand_shellcmd_onedir():
- move the code to concatenate path and pattern to expand_shellcmd().
  This allows us to slightly simplify the argument list to pass the fully
  pathed pattern and the length of the path in the pattern (0 if no path)
- factor out calls to STRMOVE()

In expand_shellcmd():
- factor out calls to STRMOVE() in the first for loop.
- reorganise the second for loop by:
  a) only calling vim_strchr() if s is not at the end of the string
  b) making sure that when the path and pattern are concatenated they fit
     inside buf
  c) concatenating path and pattern and pass to expand_shellcmd_onedir()

In globpath():
- slightly improve logic that determines if the complete path will fit
  inside the buffer

In f_getcompletion():
- replace the series of if tests with a switch
- factor out calls to STRLEN()

In copy_substring_from_pos():
- factor out the call to STRLEN()

closes: #17742

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/cmdexpand.c
src/po/vim.pot
src/version.c