Skip to content

[stdlib] Tweak comments #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/public/core/IntegerParsing.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal func _parseAsciiAsUIntMax(
else { return nil }
// Disallow < 0.
if hasMinus && result != 0 { return nil }
// Return.
// Valid result, return.
return result
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO all of these return comments are vacuous and should be deleted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dabrahams I can definitely see where you're coming from but let me explain myself :).

Rationale
The comments headings are intended for code grouping (instead of newlines) so you can quickly skim the algorithm and it's structure/flow just from those headings. The return here doesn't belong to the // Disallow < 0 code. You could separate them with a newline, but a comment is a bit more consistent with the rest of the method, and while skimming the headings conveys the fact that we early-returned all invalid results.


Expand All @@ -97,12 +97,12 @@ internal func _parseAsciiAsIntMax(
if utf16.isEmpty { return nil }
// Parse (optional) sign.
let (digitsUTF16, hasMinus) = _parseOptionalAsciiSign(utf16)
// Parse digits. +1 for because e.g. Int8's range is -128...127.
// Parse digits. +1 for negatives because e.g. Int8's range is -128...127.
let absValueMax = UIntMax(bitPattern: maximum) + (hasMinus ? 1 : 0)
guard let absValue =
_parseUnsignedAsciiAsUIntMax(digitsUTF16, radix, absValueMax)
else { return nil }
// Return signed result.
// Valid result, return signed.
return IntMax(bitPattern: hasMinus ? 0 &- absValue : absValue)
}

Expand Down