-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Foundation] add additional conformances and functionality to NSRange #7433
Conversation
@swift-ci please test |
Build failed |
|
||
// FIXME(ABI)#75 (Conditional Conformance): this API should be an extension on Range. | ||
// Can't express it now because the compiler does not support conditional | ||
// extensions with type equality constraints. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler does now support extensions with same-type constraints. The FIXME hint here looks wrong: this has nothing to do with conditional conformances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comment was not part of the additions here; it just got moved around
2228941
to
526ac56
Compare
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |
The previous build that failed was still building 2228941 instead of 526ac56 |
@swift-ci test and merge |
@swift-ci test |
Build failed |
526ac56
to
0fd0be8
Compare
@swift-ci please test |
Build failed |
Build failed |
@@ -12,33 +12,117 @@ | |||
|
|||
@_exported import Foundation // Clang module | |||
|
|||
extension NSRange : Hashable { | |||
public var hashValue: Int { | |||
return Int(bitPattern: UInt(location) ^ UInt(location)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
length
?
(Also, XOR is a pretty bad hash-combine for values that are likely to be close.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea that should have been length, I guess I could bit shift them by 32 bits and OR since NSRange (excluding NSNotFound locations) are usually very low bit values.
@@ -12,33 +12,117 @@ | |||
|
|||
@_exported import Foundation // Clang module | |||
|
|||
extension NSRange : Hashable { | |||
public var hashValue: Int { | |||
return Int(bitPattern: (UInt(bitPattern: location) | (UInt(bitPattern: length) << 32))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jrose-apple that should handle most ranges a bit better than before ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Do we care that this drops the length in 32-bit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm good point, I guess I could shift by 16 on 32 bit arches
@swift-ci please test |
Build failed |
Build failed |
…e values (and use the length too)
82125a6
to
0ab8bb3
Compare
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
@gparker42 is there a hash combine function available in the standard library? if so I would rather defer that type of thing to a single location. (granted most NSRanges are probably small values) |
NSRange is used widely in a number of Cocoa APIs; it has a few free-floating functions used to manipulate and parse ranges. These functiosn should be hoisted into NSRange and protocols should be adopted where appropriate.
NSRange can be converted to a string; therefore it should adopt
CustomStringConvertible
andCustomDebugStringConvertible
. It also has a free floating functionNSEqualRanges
which can more appropriately be expressed as adoptingEquatable
. FurthermoreNSMaxRange
can be exposed asupperBound
to fall in line withRange
. Also it can moveNSUnionRange
to be a member function to create new and mutate NSRanges.Resolves:
rdar://problem/21626767