Skip to content

Commit

Permalink
Merge pull request #77 from SimonCropp/avoid-alloc-of-sizePart-if-num…
Browse files Browse the repository at this point in the history
…berpart-is-a-match

avoid alloc of sizePart if numberpart is a match
  • Loading branch information
omar authored Sep 26, 2024
2 parents 28f1bd5 + 3156252 commit a5e2774
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ByteSizeLib/ByteSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,13 +583,13 @@ public static ByteSize Parse(string s, NumberStyles numberStyles, IFormatProvide

// Cut the input string in half
string numberPart = s.Substring(0, lastNumber).Trim();
string sizePart = s.Substring(lastNumber, s.Length - lastNumber).Trim();

// Get the numeric part
double number;
if (!double.TryParse(numberPart, numberStyles, formatProvider, out number))
throw new FormatException($"No number found in value '{s}'.");

string sizePart = s.Substring(lastNumber, s.Length - lastNumber).Trim();
// Get the magnitude part
switch (sizePart)
{
Expand Down

0 comments on commit a5e2774

Please sign in to comment.