summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-12-29 13:16:02 +0100
committerGitHub <noreply@github.com>2022-12-29 13:16:02 +0100
commite7823145f9c547d95dcb7ad23c36ffe8dff5b50d (patch)
treea0e6024a1949b9f0ae9b4ef33f8e705dea0e3681
parent497d21412aff51dd217179e4c79253e5ec6477e6 (diff)
parent96501bdbe491e0232ca74d3a3cc15c26a1716e37 (diff)
downloadrust-e7823145f9c547d95dcb7ad23c36ffe8dff5b50d.tar.gz
Rollup merge of #106216 - ChrisDenton:ps-go-faster, r=jyn514
Powershell: Use `WaitForExit` instead of `-Wait` Using the method `WaitForExit` instead of the parameter `-Wait` results in a notable speed up of the `x.ps1` script (~350ms, fairly consistently). Results: ``` milliseconds before: 1127.7576 milliseconds after: 779.0467 ``` I think there are opportunities for further speed up by calling `Get-Command` only once with the pattern `py*` then filtering the returned list. But I'll leave that for another time (or someone else). r? ``@jyn514``
-rwxr-xr-xx.ps112
1 files changed, 8 insertions, 4 deletions
diff --git a/x.ps1 b/x.ps1
index 81b98919f43..f324a4676c8 100755
--- a/x.ps1
+++ b/x.ps1
@@ -14,6 +14,12 @@ function Get-Application($app) {
return Get-Command $app -ErrorAction SilentlyContinue -CommandType Application
}
+function Invoke-Application($application, $arguments) {
+ $process = Start-Process -NoNewWindow -PassThru $application $arguments
+ $process.WaitForExit()
+ Exit $process.ExitCode
+}
+
foreach ($python in "py", "python3", "python", "python2") {
# NOTE: this only tests that the command exists in PATH, not that it's actually
# executable. The latter is not possible in a portable way, see
@@ -23,16 +29,14 @@ foreach ($python in "py", "python3", "python", "python2") {
# Use python3, not python2
$xpy_args = @("-3") + $xpy_args
}
- $process = Start-Process -NoNewWindow -Wait -PassThru $python $xpy_args
- Exit $process.ExitCode
+ Invoke-Application $python $xpy_args
}
}
$found = (Get-Application "python*" | Where-Object {$_.name -match '^python[2-3]\.[0-9]+(\.exe)?$'})
if (($null -ne $found) -and ($found.Length -ge 1)) {
$python = $found[0]
- $process = Start-Process -NoNewWindow -Wait -PassThru $python $xpy_args
- Exit $process.ExitCode
+ Invoke-Application $python $xpy_args
}
Write-Error "${PSCommandPath}: error: did not find python installed"