-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Make the rest of the scalar properties native #40233
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6136ead
Factor out the scalar bit array index mechanism
Azoy 495322a
Implement native numeric scalar properties
Azoy 57ecf25
Implement native scalar name aliases
Azoy b9b06f2
Implement native scalar mappings
Azoy 76377ca
Implement native scalar names
Azoy 12fd979
Implement native scalar age
Azoy ce0e6ff
Implement native scalar general category
Azoy a8ae6e7
Address Michael's and others comments
Azoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -849,41 +849,14 @@ extension String { | |
} | ||
} | ||
|
||
// TODO(String performance): Try out incremental case-conversion rather than | ||
// make UTF-16 array beforehand | ||
let codeUnits = Array(self.utf16).withUnsafeBufferPointer { | ||
(uChars: UnsafeBufferPointer<UInt16>) -> Array<UInt16> in | ||
var length: Int = 0 | ||
let result = Array<UInt16>(unsafeUninitializedCapacity: uChars.count) { | ||
buffer, initializedCount in | ||
var error = __swift_stdlib_U_ZERO_ERROR | ||
length = Int(truncatingIfNeeded: | ||
__swift_stdlib_u_strToLower( | ||
buffer.baseAddress._unsafelyUnwrappedUnchecked, | ||
Int32(buffer.count), | ||
uChars.baseAddress._unsafelyUnwrappedUnchecked, | ||
Int32(uChars.count), | ||
"", | ||
&error)) | ||
initializedCount = min(length, uChars.count) | ||
} | ||
if length > uChars.count { | ||
var error = __swift_stdlib_U_ZERO_ERROR | ||
return Array<UInt16>(unsafeUninitializedCapacity: length) { | ||
buffer, initializedCount in | ||
__swift_stdlib_u_strToLower( | ||
buffer.baseAddress._unsafelyUnwrappedUnchecked, | ||
Int32(buffer.count), | ||
uChars.baseAddress._unsafelyUnwrappedUnchecked, | ||
Int32(uChars.count), | ||
"", | ||
&error) | ||
initializedCount = length | ||
} | ||
} | ||
return result | ||
var result = "" | ||
result.reserveCapacity(utf8.count) | ||
|
||
for scalar in unicodeScalars { | ||
result += scalar.properties.lowercaseMapping | ||
} | ||
return codeUnits.withUnsafeBufferPointer { String._uncheckedFromUTF16($0) } | ||
|
||
return result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😭 (out of joy) |
||
} | ||
|
||
/// Returns an uppercase version of the string. | ||
|
@@ -910,41 +883,14 @@ extension String { | |
} | ||
} | ||
|
||
// TODO(String performance): Try out incremental case-conversion rather than | ||
// make UTF-16 array beforehand | ||
let codeUnits = Array(self.utf16).withUnsafeBufferPointer { | ||
(uChars: UnsafeBufferPointer<UInt16>) -> Array<UInt16> in | ||
var length: Int = 0 | ||
let result = Array<UInt16>(unsafeUninitializedCapacity: uChars.count) { | ||
buffer, initializedCount in | ||
var err = __swift_stdlib_U_ZERO_ERROR | ||
length = Int(truncatingIfNeeded: | ||
__swift_stdlib_u_strToUpper( | ||
buffer.baseAddress._unsafelyUnwrappedUnchecked, | ||
Int32(buffer.count), | ||
uChars.baseAddress._unsafelyUnwrappedUnchecked, | ||
Int32(uChars.count), | ||
"", | ||
&err)) | ||
initializedCount = min(length, uChars.count) | ||
} | ||
if length > uChars.count { | ||
var err = __swift_stdlib_U_ZERO_ERROR | ||
return Array<UInt16>(unsafeUninitializedCapacity: length) { | ||
buffer, initializedCount in | ||
__swift_stdlib_u_strToUpper( | ||
buffer.baseAddress._unsafelyUnwrappedUnchecked, | ||
Int32(buffer.count), | ||
uChars.baseAddress._unsafelyUnwrappedUnchecked, | ||
Int32(uChars.count), | ||
"", | ||
&err) | ||
initializedCount = length | ||
} | ||
} | ||
return result | ||
var result = "" | ||
result.reserveCapacity(utf8.count) | ||
|
||
for scalar in unicodeScalars { | ||
result += scalar.properties.uppercaseMapping | ||
} | ||
return codeUnits.withUnsafeBufferPointer { String._uncheckedFromUTF16($0) } | ||
|
||
return result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we have good benchmark coverage for this. This could be a nice improvement. |
||
} | ||
|
||
/// Creates an instance from the description of a given | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.