stdlib: Use config directives to work without objective-c.

Swift SVN r23211
This commit is contained in:
Graham Batty
2014-11-10 20:06:25 +00:00
parent 98586b32e5
commit dc6a776d10
27 changed files with 290 additions and 18 deletions

View File

@@ -266,6 +266,7 @@ extension String {
}
}
#if _runtime(_ObjC)
/// Compare two strings using the Unicode collation algorithm in the
/// deterministic comparison mode. (The strings which are equivalent according
/// to their NFD form are considered equal. Strings which are equivalent
@@ -284,23 +285,36 @@ extension String {
public func _stdlib_compareNSStringDeterministicUnicodeCollation(
lhs: AnyObject, rhs: AnyObject
)-> Int32
#endif
extension String: Equatable {
}
public func ==(lhs: String, rhs: String) -> Bool {
#if _runtime(_ObjC)
// Note: this operation should be consistent with equality comparison of
// Character.
return _stdlib_compareNSStringDeterministicUnicodeCollation(
lhs._bridgeToObjectiveCImpl(), rhs._bridgeToObjectiveCImpl()) == 0
#else
// FIXME: Actually implement. For now, all strings are unequal.
// rdar://problem/18878343
return false
#endif
}
extension String : Comparable {
}
public func <(lhs: String, rhs: String) -> Bool {
#if _runtime(_ObjC)
return _stdlib_compareNSStringDeterministicUnicodeCollation(
lhs._bridgeToObjectiveCImpl(), rhs._bridgeToObjectiveCImpl()) < 0
#else
// FIXME: Actually implement. For now, all strings are unequal
// rdar://problem/18878343
return false
#endif
}
// Support for copy-on-write
@@ -327,8 +341,10 @@ extension String {
}
}
#if _runtime(_ObjC)
@asmname("swift_stdlib_NSStringNFDHashValue")
func _stdlib_NSStringNFDHashValue(str: AnyObject) -> Int
#endif
extension String : Hashable {
/// The hash value.
@@ -346,11 +362,17 @@ extension String : Hashable {
#else
let hashOffset = 0x429b126688ddcc21
#endif
#if _runtime(_ObjC)
// FIXME(performance): constructing a temporary NSString is extremely
// wasteful and inefficient.
let cocoaString =
unsafeBitCast(self._bridgeToObjectiveCImpl(), _NSStringCoreType.self)
return hashOffset ^ _stdlib_NSStringNFDHashValue(cocoaString)
#else
// FIXME: Actually implement. For now, all strings have the same hash.
// rdar://problem/18878343
return hashOffset
#endif
}
}
@@ -392,10 +414,6 @@ public func += (inout lhs: String, rhs: String) {
}
}
// Comparison operators
extension String : Comparable {
}
extension String {
/// Low-level construction interface used by introspection
/// implementation in the runtime library. Constructs a String in