//===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// import SwiftShims extension _UnmanagedString where CodeUnit == UInt8 { internal func hashASCII(into core: inout _Hasher.Core) { core.combine(bytes: rawBuffer) } } extension BidirectionalCollection where Element == UInt16, SubSequence == Self { internal func hashUTF16(into core: inout _Hasher.Core) { for i in self.indices { let cu = self[i] let cuIsASCII = cu <= 0x7F let isSingleSegmentScalar = self.hasNormalizationBoundary(after: i) if cuIsASCII && isSingleSegmentScalar { core.combine(UInt8(truncatingIfNeeded: cu)) } else { for encodedScalar in Unicode._ParsingIterator( codeUnits: _NormalizedCodeUnitIterator(self[i.., into hasher: inout _Hasher) { if _isSmall { _smallUTF8String[range].hash(into: &hasher) return } defer { _fixLifetime(self) } if _slowPath(_isOpaque) { _asOpaque()[range].hash(into: &hasher) return } if isASCII { _unmanagedASCIIView[range].hash(into: &hasher) return } _unmanagedUTF16View[range].hash(into: &hasher) } } extension String : Hashable { /// The string's hash value. /// /// Hash values are not guaranteed to be equal across different executions of /// your program. Do not save hash values to use during a future execution. @inlinable public var hashValue: Int { return _hashValue(for: self) } @inlinable public func _hash(into hasher: inout _Hasher) { _guts._hash(into: &hasher) } } extension StringProtocol { @inlinable public var hashValue : Int { return _hashValue(for: self) } @inlinable public func _hash(into hasher: inout _Hasher) { _wholeString._guts._hash(_encodedOffsetRange, into: &hasher) } }