Skip to content

[stdlib] Make _parseASCII take radix as Int instead of FixedWidthInteger #26961

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
12 changes: 6 additions & 6 deletions stdlib/public/core/IntegerParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ where Rest.Element: UnsignedInteger {
internal func _parseASCII<
CodeUnits: IteratorProtocol, Result: FixedWidthInteger
>(
codeUnits: inout CodeUnits, radix: Result
codeUnits: inout CodeUnits, radix: Int
) -> Result?
where CodeUnits.Element: UnsignedInteger {
let c0_ = codeUnits.next()
guard _fastPath(c0_ != nil), let c0 = c0_ else { return nil }
if _fastPath(c0 != _ascii16("+") && c0 != _ascii16("-")) {
return _parseUnsignedASCII(
first: c0, rest: &codeUnits, radix: radix, positive: true)
first: c0, rest: &codeUnits, radix: radix, positive: true) as? Result
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a clear indication that this is not a full solution; _parseUnsignedASCII should still be returning a Result, so this cast shouldn't be necessary.

Copy link
Member

Choose a reason for hiding this comment

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

@theblixguy Looks to me like you'll need to propagate the radix: Result -> radix: Int change throughout all the internal methods in this file.

}
let c1_ = codeUnits.next()
guard _fastPath(c1_ != nil), let c1 = c1_ else { return nil }
if _fastPath(c0 == _ascii16("-")) {
return _parseUnsignedASCII(
first: c1, rest: &codeUnits, radix: radix, positive: false)
first: c1, rest: &codeUnits, radix: radix, positive: false) as? Result
}
else {
return _parseUnsignedASCII(
first: c1, rest: &codeUnits, radix: radix, positive: true)
first: c1, rest: &codeUnits, radix: radix, positive: true) as? Result
}
}

Expand All @@ -111,7 +111,7 @@ extension FixedWidthInteger {
codeUnits: inout CodeUnits, radix: Result
) -> Result?
where CodeUnits.Element: UnsignedInteger {
return _parseASCII(codeUnits: &codeUnits, radix: radix)
return _parseASCII(codeUnits: &codeUnits, radix: Int(radix))
}

/// Creates a new integer value from the given string and radix.
Expand Down Expand Up @@ -154,7 +154,7 @@ extension FixedWidthInteger {
if let str = text as? String, str._guts.isFastUTF8 {
guard let ret = str._guts.withFastUTF8 ({ utf8 -> Self? in
var iter = utf8.makeIterator()
return _parseASCII(codeUnits: &iter, radix: Self(radix))
return _parseASCII(codeUnits: &iter, radix: radix)
}) else {
return nil
}
Expand Down