cmFindProgramCommand: Only collapse failed paths when search fails
This reduces the calls to SystemToolsStatic::GetActualCaseForPathCached
(issues: #20214 and #24113) for finding programs and yields a nice speedup when configuring CMake itself:
> hyperfine -p 'rmdir /S /Q build-perf || true' '.\build-msvc-release\bin\cmake.exe -G Ninja -B build-perf -D CMAKE_BUILD_TYPE=Debug' '.\build-msvc-release-base\bin\cmake.exe -G Ninja -B build-perf-base -D CMAKE_BUILD_TYPE=Debug' -p 'rmdir /S /Q build-perf-base || true'
Benchmark 1: .\build-msvc-release\bin\cmake.exe -G Ninja -B build-perf -D CMAKE_BUILD_TYPE=Debug
Time (mean ± σ): 33.224 s ± 0.132 s [User: 15.595 s, System: 17.574 s]
Range (min … max): 33.040 s … 33.379 s 10 runs
Benchmark 2: .\build-msvc-release-base\bin\cmake.exe -G Ninja -B build-perf-base -D CMAKE_BUILD_TYPE=Debug
Time (mean ± σ): 34.071 s ± 0.093 s [User: 15.951 s, System: 18.321 s]
Range (min … max): 33.936 s … 34.240 s 10 runs
Summary
'.\build-msvc-release\bin\cmake.exe -G Ninja -B build-perf -D CMAKE_BUILD_TYPE=Debug' ran
1.03 ± 0.00 times faster than '.\build-msvc-release-base\bin\cmake.exe -G Ninja -B build-perf-base -D CMAKE_BUILD_TYPE=Debug'