Skip to content

Commit 087b952

Browse files
committed
Refactored TryParseLongFast(...)
1 parent 2fa56e5 commit 087b952

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

BencodeNET.Net45/Bencode.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,19 +451,12 @@ private static bool TryParseLongFast(string value, out long result)
451451
if (length == 0)
452452
return false;
453453

454-
var startIndex = 0;
455-
var isNegative = false;
454+
var isNegative = value[0] == '-';
455+
var startIndex = isNegative ? 1 : 0;
456456

457-
// Check if negative and set startIndex accordingly
458-
if (value[0] == '-')
459-
{
460-
// Cannot parse just '-'
461-
if (length == 1)
462-
return false;
463-
464-
isNegative = true;
465-
startIndex = 1;
466-
}
457+
// Cannot parse just '-'
458+
if (isNegative && length == 1)
459+
return false;
467460

468461
// Cannot parse string longer than long.MaxValue
469462
if (length - startIndex > Int64MaxDigits)

0 commit comments

Comments
 (0)