From 17c6c2660c9db80c210a9c5bae249d7de08260fb Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 17 Feb 2020 00:01:56 -0500 Subject: [PATCH] Use double.Parse on span instead of string in Unix ping (#32423) Avoids a string allocation. --- .../src/System/Net/NetworkInformation/UnixCommandLinePing.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/Common/src/System/Net/NetworkInformation/UnixCommandLinePing.cs b/src/libraries/Common/src/System/Net/NetworkInformation/UnixCommandLinePing.cs index d1636491c2775..157986f7bf649 100644 --- a/src/libraries/Common/src/System/Net/NetworkInformation/UnixCommandLinePing.cs +++ b/src/libraries/Common/src/System/Net/NetworkInformation/UnixCommandLinePing.cs @@ -156,8 +156,8 @@ public static long ParseRoundTripTime(string pingOutput) int afterTime = timeIndex + "time=".Length; int msIndex = pingOutput.IndexOf("ms", afterTime, StringComparison.Ordinal); int numLength = msIndex - afterTime - 1; - string timeSubstring = pingOutput.Substring(afterTime, numLength); - double parsedRtt = double.Parse(timeSubstring, CultureInfo.InvariantCulture); + ReadOnlySpan timeSubstring = pingOutput.AsSpan(afterTime, numLength); + double parsedRtt = double.Parse(timeSubstring, provider: CultureInfo.InvariantCulture); return (long)Math.Round(parsedRtt); } }