diff --git a/stdlib/public/core/ASCII.swift b/stdlib/public/core/ASCII.swift index 27b9efde18d18..850ca8b29e438 100644 --- a/stdlib/public/core/ASCII.swift +++ b/stdlib/public/core/ASCII.swift @@ -20,26 +20,24 @@ extension Unicode.ASCII : Unicode.Encoding { @inlinable public static var encodedReplacementCharacter : EncodedScalar { - return EncodedScalar(0x1a) // U+001A SUBSTITUTE; best we can do for ASCII + EncodedScalar(0x1a) // U+001A SUBSTITUTE; best we can do for ASCII } /// Returns whether the given code unit represents an ASCII scalar @_alwaysEmitIntoClient - public static func isASCII(_ x: CodeUnit) -> Bool { return UTF8.isASCII(x) } + public static func isASCII(_ x: CodeUnit) -> Bool { UTF8.isASCII(x) } @inline(__always) @inlinable - public static func _isScalar(_ x: CodeUnit) -> Bool { - return true - } + public static func _isScalar(_ x: CodeUnit) -> Bool { true } @inline(__always) @inlinable public static func decode(_ source: EncodedScalar) -> Unicode.Scalar { - return Unicode.Scalar(_unchecked: UInt32( + Unicode.Scalar(_unchecked: UInt32( source.first._unsafelyUnwrappedUnchecked)) } - + @inline(__always) @inlinable public static func encode( @@ -73,7 +71,7 @@ extension Unicode.ASCII : Unicode.Encoding { @inlinable public init() { } } - + public typealias ForwardParser = Parser public typealias ReverseParser = Parser } diff --git a/stdlib/public/core/CString.swift b/stdlib/public/core/CString.swift index 2e49c41527ad0..b451ba3e41f25 100644 --- a/stdlib/public/core/CString.swift +++ b/stdlib/public/core/CString.swift @@ -187,19 +187,15 @@ extension String { } extension UnsafePointer where Pointee == UInt8 { - @inlinable + @inlinable @inline(__always) internal var _asCChar: UnsafePointer { - @inline(__always) get { - return UnsafeRawPointer(self).assumingMemoryBound(to: CChar.self) - } + UnsafeRawPointer(self).assumingMemoryBound(to: CChar.self) } } extension UnsafePointer where Pointee == CChar { - @inlinable + @inlinable @inline(__always) internal var _asUInt8: UnsafePointer { - @inline(__always) get { - return UnsafeRawPointer(self).assumingMemoryBound(to: UInt8.self) - } + UnsafeRawPointer(self).assumingMemoryBound(to: UInt8.self) } } diff --git a/stdlib/public/core/SmallString.swift b/stdlib/public/core/SmallString.swift index c3a973acfa5e7..205740950acf5 100644 --- a/stdlib/public/core/SmallString.swift +++ b/stdlib/public/core/SmallString.swift @@ -33,17 +33,17 @@ internal struct _SmallString { internal var _storage: RawBitPattern @inlinable @inline(__always) - internal var rawBits: RawBitPattern { return _storage } + internal var rawBits: RawBitPattern { _storage } @inlinable internal var leadingRawBits: UInt64 { - @inline(__always) get { return _storage.0 } + @inline(__always) get { _storage.0 } @inline(__always) set { _storage.0 = newValue } } @inlinable internal var trailingRawBits: UInt64 { - @inline(__always) get { return _storage.1 } + @inline(__always) get { _storage.1 } @inline(__always) set { _storage.1 = newValue } } @@ -88,23 +88,23 @@ extension _SmallString { @inlinable @inline(__always) internal var rawDiscriminatedObject: UInt64 { // Reverse the bytes on big-endian systems. - return _storage.1.littleEndian + _storage.1.littleEndian } @inlinable @inline(__always) - internal var capacity: Int { return _SmallString.capacity } + internal var capacity: Int { _SmallString.capacity } @inlinable @inline(__always) internal var count: Int { - return _StringObject.getSmallCount(fromRaw: rawDiscriminatedObject) + _StringObject.getSmallCount(fromRaw: rawDiscriminatedObject) } @inlinable @inline(__always) - internal var unusedCapacity: Int { return capacity &- count } + internal var unusedCapacity: Int { capacity &- count } @inlinable @inline(__always) internal var isASCII: Bool { - return _StringObject.getSmallIsASCII(fromRaw: rawDiscriminatedObject) + _StringObject.getSmallIsASCII(fromRaw: rawDiscriminatedObject) } // Give raw, nul-terminated code units. This is only for limited internal @@ -157,10 +157,10 @@ extension _SmallString: RandomAccessCollection, MutableCollection { internal typealias SubSequence = _SmallString @inlinable @inline(__always) - internal var startIndex: Int { return 0 } + internal var startIndex: Int { 0 } @inlinable @inline(__always) - internal var endIndex: Int { return count } + internal var endIndex: Int { count } @inlinable internal subscript(_ idx: Int) -> UInt8 { @@ -185,7 +185,7 @@ extension _SmallString: RandomAccessCollection, MutableCollection { @inlinable @inline(__always) internal subscript(_ bounds: Range) -> SubSequence { // TODO(String performance): In-vector-register operation - return self.withUTF8 { utf8 in + self.withUTF8 { utf8 in let rebased = UnsafeBufferPointer(rebasing: utf8[bounds]) return _SmallString(rebased)._unsafelyUnwrappedUnchecked } diff --git a/stdlib/public/core/StaticString.swift b/stdlib/public/core/StaticString.swift index 5298682d7d2db..8ff51f5ca7af4 100644 --- a/stdlib/public/core/StaticString.swift +++ b/stdlib/public/core/StaticString.swift @@ -97,9 +97,7 @@ public struct StaticString /// A Boolean value indicating whether the static string stores a pointer to /// ASCII or UTF-8 code units. @_transparent - public var hasPointerRepresentation: Bool { - return (UInt8(_flags) & 0x1) == 0 - } + public var hasPointerRepresentation: Bool { (UInt8(_flags) & 0x1) == 0 } /// A Boolean value that is `true` if the static string stores a pointer to /// ASCII code units. @@ -111,9 +109,7 @@ public struct StaticString /// - Warning: If the static string stores a single Unicode scalar value, the /// value of `isASCII` is unspecified. @_transparent - public var isASCII: Bool { - return (UInt8(_flags) & 0x2) != 0 - } + public var isASCII: Bool { (UInt8(_flags) & 0x2) != 0 } /// Invokes the given closure with a buffer containing the static string's /// UTF-8 code unit sequence. @@ -253,17 +249,13 @@ public struct StaticString /// A string representation of the static string. public var description: String { - return withUTF8Buffer { String._uncheckedFromUTF8($0) } + withUTF8Buffer { String._uncheckedFromUTF8($0) } } /// A textual representation of the static string, suitable for debugging. - public var debugDescription: String { - return self.description.debugDescription - } + public var debugDescription: String { self.description.debugDescription } } extension StaticString { - public var customMirror: Mirror { - return Mirror(reflecting: description) - } + public var customMirror: Mirror { Mirror(reflecting: description) } } diff --git a/stdlib/public/core/String.swift b/stdlib/public/core/String.swift index 2b1750950668b..53a1ec3cc58ad 100644 --- a/stdlib/public/core/String.swift +++ b/stdlib/public/core/String.swift @@ -595,7 +595,7 @@ extension Sequence where Element: StringProtocol { @_specialize(where Self == Array) @_specialize(where Self == Array) public func joined(separator: String = "") -> String { - return _joined(separator: separator) + _joined(separator: separator) } @inline(__always) // Pick up @_specialize and devirtualize from two callers @@ -645,7 +645,7 @@ extension BidirectionalCollection where Element == String { /// - Returns: A single, concatenated string. @_specialize(where Self == Array) public func joined(separator: String = "") -> String { - return _joined(separator: separator) + _joined(separator: separator) } } @@ -836,7 +836,7 @@ extension String: CustomStringConvertible { /// Using this property directly is discouraged. Instead, use simple /// assignment to create a new constant or variable equal to this string. @inlinable - public var description: String { return self } + public var description: String { self } } extension String { @@ -889,12 +889,12 @@ extension _StringGutsSlice { var outputBuffer = outputBuffer var icuInputBuffer = icuInputBuffer var icuOutputBuffer = icuOutputBuffer - + var index = range.lowerBound let cachedEndIndex = range.upperBound - + var hasBufferOwnership = false - + defer { if hasBufferOwnership { outputBuffer.deallocate() @@ -902,7 +902,7 @@ extension _StringGutsSlice { icuOutputBuffer.deallocate() } } - + while index < cachedEndIndex { let result = _foreignNormalize( readIndex: index, @@ -938,9 +938,9 @@ internal func _fastWithNormalizedCodeUnitsImpl( var index = String.Index(_encodedOffset: 0) let cachedEndIndex = String.Index(_encodedOffset: sourceBuffer.count) - + var hasBufferOwnership = false - + defer { if hasBufferOwnership { outputBuffer.deallocate() @@ -948,7 +948,7 @@ internal func _fastWithNormalizedCodeUnitsImpl( icuOutputBuffer.deallocate() } } - + while index < cachedEndIndex { let result = _fastNormalize( readIndex: index, diff --git a/stdlib/public/core/StringBreadcrumbs.swift b/stdlib/public/core/StringBreadcrumbs.swift index 1ecae71618eda..1a32fb16f4fd7 100644 --- a/stdlib/public/core/StringBreadcrumbs.swift +++ b/stdlib/public/core/StringBreadcrumbs.swift @@ -62,16 +62,15 @@ internal final class _StringBreadcrumbs { } extension _StringBreadcrumbs { - var stride: Int { - @inline(__always) get { return _StringBreadcrumbs.breadcrumbStride } - } + @inline(__always) + var stride: Int { _StringBreadcrumbs.breadcrumbStride } // Fetch the lower-bound index corresponding to the given offset, returning // the index and the remaining offset to adjust internal func getBreadcrumb( forOffset offset: Int ) -> (lowerBound: String.Index, remaining: Int) { - return (crumbs[offset / stride], offset % stride) + (crumbs[offset / stride], offset % stride) } // Fetch the lower-bound offset corresponding to the given index, returning diff --git a/stdlib/public/core/StringBridge.swift b/stdlib/public/core/StringBridge.swift index 759f2780ff223..6c847c169d2d7 100644 --- a/stdlib/public/core/StringBridge.swift +++ b/stdlib/public/core/StringBridge.swift @@ -35,7 +35,7 @@ internal func _stdlib_binary_CFStringCreateCopy( internal func _stdlib_binary_CFStringGetLength( _ source: _CocoaString ) -> Int { - return _swift_stdlib_CFStringGetLength(source) + _swift_stdlib_CFStringGetLength(source) } @usableFromInline // @testable @@ -43,7 +43,7 @@ internal func _stdlib_binary_CFStringGetLength( internal func _stdlib_binary_CFStringGetCharactersPtr( _ source: _CocoaString ) -> UnsafeMutablePointer? { - return UnsafeMutablePointer( + UnsafeMutablePointer( mutating: _swift_stdlib_CFStringGetCharactersPtr(source)) } @@ -103,14 +103,14 @@ internal func _cocoaStringCompare( internal func _cocoaHashString( _ string: _CocoaString ) -> UInt { - return _swift_stdlib_CFStringHashNSString(string) + _swift_stdlib_CFStringHashNSString(string) } @_effects(readonly) internal func _cocoaHashASCIIBytes( _ bytes: UnsafePointer, length: Int ) -> UInt { - return _swift_stdlib_CFStringHashCString(bytes, length) + _swift_stdlib_CFStringHashCString(bytes, length) } // These "trampolines" are effectively objc_msgSend_super. @@ -120,7 +120,7 @@ internal func _cocoaHashASCIIBytes( internal func _cocoaCStringUsingEncodingTrampoline( _ string: _CocoaString, _ encoding: UInt ) -> UnsafePointer? { - return _swift_stdlib_NSStringCStringUsingEncodingTrampoline(string, encoding) + _swift_stdlib_NSStringCStringUsingEncodingTrampoline(string, encoding) } @_effects(releasenone) @@ -130,7 +130,7 @@ internal func _cocoaGetCStringTrampoline( _ maxLength: Int, _ encoding: UInt ) -> Int8 { - return Int8(_swift_stdlib_NSStringGetCStringTrampoline( + Int8(_swift_stdlib_NSStringGetCStringTrampoline( string, buffer, maxLength, encoding)) } @@ -138,13 +138,11 @@ internal func _cocoaGetCStringTrampoline( // Conversion from NSString to Swift's native representation. // -private var kCFStringEncodingASCII : _swift_shims_CFStringEncoding { - @inline(__always) get { return 0x0600 } -} +@inline(__always) +private var kCFStringEncodingASCII : _swift_shims_CFStringEncoding { 0x0600 } -private var kCFStringEncodingUTF8 : _swift_shims_CFStringEncoding { - @inline(__always) get { return 0x8000100 } -} +@inline(__always) +private var kCFStringEncodingUTF8 : _swift_shims_CFStringEncoding { 0x8000100 } internal enum _KnownCocoaString { case storage @@ -153,17 +151,17 @@ internal enum _KnownCocoaString { #if !(arch(i386) || arch(arm)) case tagged #endif - + @inline(__always) init(_ str: _CocoaString) { - + #if !(arch(i386) || arch(arm)) if _isObjCTaggedPointer(str) { self = .tagged return } #endif - + switch unsafeBitCast(_swift_classOfObjCHeapObject(str), to: UInt.self) { case unsafeBitCast(__StringStorage.self, to: UInt.self): self = .storage @@ -252,13 +250,13 @@ internal func _bridgeCocoaString(_ cocoaString: _CocoaString) -> _StringGuts { // 3) If it's mutable with associated information, must make the call let immutableCopy = _stdlib_binary_CFStringCreateCopy(cocoaString) as AnyObject - + #if !(arch(i386) || arch(arm)) if _isObjCTaggedPointer(immutableCopy) { return _StringGuts(_SmallString(taggedCocoa: immutableCopy)) } #endif - + let (fastUTF8, isASCII): (Bool, Bool) switch _getCocoaStringPointer(immutableCopy) { case .ascii(_): (fastUTF8, isASCII) = (true, true) @@ -266,7 +264,7 @@ internal func _bridgeCocoaString(_ cocoaString: _CocoaString) -> _StringGuts { default: (fastUTF8, isASCII) = (false, false) } let length = _stdlib_binary_CFStringGetLength(immutableCopy) - + return _StringGuts( cocoa: immutableCopy, providesFastUTF8: fastUTF8, @@ -288,7 +286,7 @@ private func _createCFString( _ count: Int, _ encoding: UInt32 ) -> AnyObject { - return _swift_stdlib_CFStringCreateWithBytes( + _swift_stdlib_CFStringCreateWithBytes( nil, //ignored in the shim for perf reasons ptr, count, @@ -342,7 +340,7 @@ class __SwiftNativeNSString { // as an NSString. @_silgen_name("swift_stdlib_getDescription") public func _getDescription(_ x: T) -> AnyObject { - return String(reflecting: x)._bridgeToObjectiveCImpl() + String(reflecting: x)._bridgeToObjectiveCImpl() } #else // !_runtime(_ObjC) @@ -361,14 +359,14 @@ extension StringProtocol { @_specialize(where Self == Substring) public // SPI(Foundation) func _toUTF16Offset(_ idx: Index) -> Int { - return self.utf16.distance(from: self.utf16.startIndex, to: idx) + self.utf16.distance(from: self.utf16.startIndex, to: idx) } @_specialize(where Self == String) @_specialize(where Self == Substring) public // SPI(Foundation) func _toUTF16Index(_ offset: Int) -> Index { - return self.utf16.index(self.utf16.startIndex, offsetBy: offset) + self.utf16.index(self.utf16.startIndex, offsetBy: offset) } @_specialize(where Self == String) diff --git a/stdlib/public/core/StringCharacterView.swift b/stdlib/public/core/StringCharacterView.swift index 826cce98b1b23..2cd06fec0d8f7 100644 --- a/stdlib/public/core/StringCharacterView.swift +++ b/stdlib/public/core/StringCharacterView.swift @@ -36,20 +36,18 @@ extension String: BidirectionalCollection { /// /// In an empty string, `startIndex` is equal to `endIndex`. @inlinable @inline(__always) - public var startIndex: Index { return _guts.startIndex } + public var startIndex: Index { _guts.startIndex } /// A string's "past the end" position---that is, the position one greater /// than the last valid subscript argument. /// /// In an empty string, `endIndex` is equal to `startIndex`. @inlinable @inline(__always) - public var endIndex: Index { return _guts.endIndex } + public var endIndex: Index { _guts.endIndex } /// The number of characters in a string. @inline(__always) - public var count: Int { - return distance(from: startIndex, to: endIndex) - } + public var count: Int { distance(from: startIndex, to: endIndex) } /// Returns the position immediately after the given index. /// @@ -107,7 +105,7 @@ extension String: BidirectionalCollection { @inlinable @inline(__always) public func index(_ i: Index, offsetBy n: IndexDistance) -> Index { // TODO: known-ASCII and single-scalar-grapheme fast path, etc. - return _index(i, offsetBy: n) + _index(i, offsetBy: n) } /// Returns an index that is the specified distance from the given index, @@ -152,7 +150,7 @@ extension String: BidirectionalCollection { _ i: Index, offsetBy n: IndexDistance, limitedBy limit: Index ) -> Index? { // TODO: known-ASCII and single-scalar-grapheme fast path, etc. - return _index(i, offsetBy: n, limitedBy: limit) + _index(i, offsetBy: n, limitedBy: limit) } /// Returns the distance between two indices. @@ -167,7 +165,7 @@ extension String: BidirectionalCollection { @inlinable @inline(__always) public func distance(from start: Index, to end: Index) -> IndexDistance { // TODO: known-ASCII and single-scalar-grapheme fast path, etc. - return _distance(from: start, to: end) + _distance(from: start, to: end) } /// Accesses the character at the given position. @@ -245,8 +243,6 @@ extension String { } @inlinable - public __consuming func makeIterator() -> Iterator { - return Iterator(_guts) - } + public __consuming func makeIterator() -> Iterator { Iterator(_guts) } } diff --git a/stdlib/public/core/StringComparable.swift b/stdlib/public/core/StringComparable.swift index 4ab70ade658a0..e74131a1fd129 100644 --- a/stdlib/public/core/StringComparable.swift +++ b/stdlib/public/core/StringComparable.swift @@ -20,7 +20,7 @@ extension StringProtocol { @_specialize(where Self == Substring, RHS == Substring) @_effects(readonly) public static func == (lhs: Self, rhs: RHS) -> Bool { - return _stringCompare( + _stringCompare( lhs._wholeGuts, lhs._offsetRange, rhs._wholeGuts, rhs._offsetRange, expecting: .equal) @@ -29,7 +29,7 @@ extension StringProtocol { @inlinable @inline(__always) // forward to other operator @_effects(readonly) public static func != (lhs: Self, rhs: RHS) -> Bool { - return !(lhs == rhs) + !(lhs == rhs) } @inlinable @@ -39,7 +39,7 @@ extension StringProtocol { @_specialize(where Self == Substring, RHS == Substring) @_effects(readonly) public static func < (lhs: Self, rhs: RHS) -> Bool { - return _stringCompare( + _stringCompare( lhs._wholeGuts, lhs._offsetRange, rhs._wholeGuts, rhs._offsetRange, expecting: .less) @@ -48,19 +48,19 @@ extension StringProtocol { @inlinable @inline(__always) // forward to other operator @_effects(readonly) public static func > (lhs: Self, rhs: RHS) -> Bool { - return rhs < lhs + rhs < lhs } @inlinable @inline(__always) // forward to other operator @_effects(readonly) public static func <= (lhs: Self, rhs: RHS) -> Bool { - return !(rhs < lhs) + !(rhs < lhs) } @inlinable @inline(__always) // forward to other operator @_effects(readonly) public static func >= (lhs: Self, rhs: RHS) -> Bool { - return !(lhs < rhs) + !(lhs < rhs) } } @@ -69,7 +69,7 @@ extension String : Equatable { @_effects(readonly) @_semantics("string.equals") public static func == (lhs: String, rhs: String) -> Bool { - return _stringCompare(lhs._guts, rhs._guts, expecting: .equal) + _stringCompare(lhs._guts, rhs._guts, expecting: .equal) } } @@ -77,7 +77,7 @@ extension String : Comparable { @inlinable @inline(__always) // For the bitwise comparision @_effects(readonly) public static func < (lhs: String, rhs: String) -> Bool { - return _stringCompare(lhs._guts, rhs._guts, expecting: .less) + _stringCompare(lhs._guts, rhs._guts, expecting: .less) } } diff --git a/stdlib/public/core/StringComparison.swift b/stdlib/public/core/StringComparison.swift index 3eceb4b01e2a0..b99538ae1ff4b 100644 --- a/stdlib/public/core/StringComparison.swift +++ b/stdlib/public/core/StringComparison.swift @@ -170,7 +170,7 @@ private func _stringCompareFastUTF8Abnormal( private func _stringCompareSlow( _ lhs: _StringGuts, _ rhs: _StringGuts, expecting: _StringComparisonResult ) -> Bool { - return _stringCompareSlow( + _stringCompareSlow( lhs, 0.. Bool { // TODO: Just call the normalizer directly with range - return _StringGutsSlice(lhs, lhsRange).compare( + _StringGutsSlice(lhs, lhsRange).compare( with: _StringGutsSlice(rhs, rhsRange), expecting: expecting) } @@ -222,7 +222,7 @@ private func _findDiffIdx( private func _lexicographicalCompare( _ lhs: I, _ rhs: I, expecting: _StringComparisonResult ) -> Bool { - return expecting == .equal ? lhs == rhs : lhs < rhs + expecting == .equal ? lhs == rhs : lhs < rhs } @_effects(readonly) @@ -391,8 +391,8 @@ extension _StringGutsSlice { }) } } - - + + @inline(__always) //Avoid unecessary overhead from the closures. internal func _normalizedCompareImpl( left_outputBuffer: UnsafeMutableBufferPointer, @@ -421,7 +421,7 @@ extension _StringGutsSlice { var right_outputBuffer = right_outputBuffer var right_icuInputBuffer = right_icuInputBuffer var right_icuOutputBuffer = right_icuOutputBuffer - + var leftNextReadPosition = left_range.lowerBound var rightNextReadPosition = right_range.lowerBound var leftOutputBufferIndex = 0 @@ -430,10 +430,10 @@ extension _StringGutsSlice { var rightOutputBufferCount = 0 let leftEndIndex = left_range.upperBound let rightEndIndex = right_range.upperBound - + var hasLeftBufferOwnership = false var hasRightBufferOwnership = false - + if left_range.isEmpty && right_range.isEmpty { return expecting == .equal } @@ -443,7 +443,7 @@ extension _StringGutsSlice { if right_range.isEmpty { return false } - + defer { if hasLeftBufferOwnership { left_outputBuffer.deallocate() @@ -456,7 +456,7 @@ extension _StringGutsSlice { right_icuOutputBuffer.deallocate() } } - + repeat { if leftOutputBufferIndex == leftOutputBufferCount { let result = normalizeLeft( @@ -505,10 +505,10 @@ extension _StringGutsSlice { || leftOutputBufferIndex < leftOutputBufferCount) && (rightNextReadPosition < rightEndIndex || rightOutputBufferIndex < rightOutputBufferCount) - - + + //At least one of them ran out of code units, whichever it was is the "smaller" string - if leftNextReadPosition < leftEndIndex + if leftNextReadPosition < leftEndIndex || leftOutputBufferIndex < leftOutputBufferCount { return false } else if rightNextReadPosition < rightEndIndex diff --git a/stdlib/public/core/StringCreate.swift b/stdlib/public/core/StringCreate.swift index 62d725766927b..217f5301c41fd 100644 --- a/stdlib/public/core/StringCreate.swift +++ b/stdlib/public/core/StringCreate.swift @@ -91,7 +91,7 @@ extension String { internal static func _uncheckedFromUTF8( _ input: UnsafeBufferPointer ) -> String { - return _uncheckedFromUTF8(input, isASCII: _allASCII(input)) + _uncheckedFromUTF8(input, isASCII: _allASCII(input)) } @usableFromInline @@ -176,7 +176,7 @@ extension String { static func _fromInvalidUTF16( _ utf16: UnsafeBufferPointer ) -> String { - return String._fromCodeUnits(utf16, encoding: UTF16.self, repair: true)!.0 + String._fromCodeUnits(utf16, encoding: UTF16.self, repair: true)!.0 } @usableFromInline @@ -193,7 +193,7 @@ extension String { @_alwaysEmitIntoClient @inline(never) // slow-path internal static func _copying(_ str: String) -> String { - return String._copying(str[...]) + String._copying(str[...]) } @_alwaysEmitIntoClient @inline(never) // slow-path diff --git a/stdlib/public/core/StringGraphemeBreaking.swift b/stdlib/public/core/StringGraphemeBreaking.swift index 21222e8c4e7d5..54b089bba33b0 100644 --- a/stdlib/public/core/StringGraphemeBreaking.swift +++ b/stdlib/public/core/StringGraphemeBreaking.swift @@ -13,8 +13,8 @@ import SwiftShims /// CR and LF are common special cases in grapheme breaking logic -private var _CR: UInt8 { return 0x0d } -private var _LF: UInt8 { return 0x0a } +private var _CR: UInt8 { 0x0d } +private var _LF: UInt8 { 0x0a } private func _hasGraphemeBreakBetween( _ lhs: Unicode.Scalar, _ rhs: Unicode.Scalar diff --git a/stdlib/public/core/StringGuts.swift b/stdlib/public/core/StringGuts.swift index 7fb09aa06102a..b2485bc48fc4f 100644 --- a/stdlib/public/core/StringGuts.swift +++ b/stdlib/public/core/StringGuts.swift @@ -38,9 +38,7 @@ struct _StringGuts { // Raw extension _StringGuts { @inlinable @inline(__always) - internal var rawBits: _StringObject.RawBitPattern { - return _object.rawBits - } + internal var rawBits: _StringObject.RawBitPattern { _object.rawBits } } // Creation @@ -79,50 +77,40 @@ extension _StringGuts { extension _StringGuts { // The number of code units @inlinable @inline(__always) - internal var count: Int { return _object.count } + internal var count: Int { _object.count } @inlinable @inline(__always) - internal var isEmpty: Bool { return count == 0 } + internal var isEmpty: Bool { count == 0 } @inlinable @inline(__always) - internal var isSmall: Bool { return _object.isSmall } + internal var isSmall: Bool { _object.isSmall } @inline(__always) - internal var isSmallASCII: Bool { - return _object.isSmall && _object.smallIsASCII - } + internal var isSmallASCII: Bool { _object.isSmall && _object.smallIsASCII } @inlinable @inline(__always) - internal var asSmall: _SmallString { - return _SmallString(_object) - } + internal var asSmall: _SmallString { _SmallString(_object) } @inlinable @inline(__always) - internal var isASCII: Bool { - return _object.isASCII - } + internal var isASCII: Bool { _object.isASCII } @inlinable @inline(__always) - internal var isFastASCII: Bool { - return isFastUTF8 && _object.isASCII - } + internal var isFastASCII: Bool { isFastUTF8 && _object.isASCII } @inline(__always) - internal var isNFC: Bool { return _object.isNFC } + internal var isNFC: Bool { _object.isNFC } @inline(__always) internal var isNFCFastUTF8: Bool { // TODO(String micro-performance): Consider a dedicated bit for this - return _object.isNFC && isFastUTF8 + _object.isNFC && isFastUTF8 } - internal var hasNativeStorage: Bool { return _object.hasNativeStorage } + internal var hasNativeStorage: Bool { _object.hasNativeStorage } - internal var hasSharedStorage: Bool { return _object.hasSharedStorage } + internal var hasSharedStorage: Bool { _object.hasSharedStorage } - internal var hasBreadcrumbs: Bool { - return hasNativeStorage || hasSharedStorage - } + internal var hasBreadcrumbs: Bool { hasNativeStorage || hasSharedStorage } } // @@ -130,13 +118,11 @@ extension _StringGuts { // Whether we can provide fast access to contiguous UTF-8 code units @_transparent @inlinable - internal var isFastUTF8: Bool { return _fastPath(_object.providesFastUTF8) } + internal var isFastUTF8: Bool { _fastPath(_object.providesFastUTF8) } // A String which does not provide fast access to contiguous UTF-8 code units @inlinable @inline(__always) - internal var isForeign: Bool { - return _slowPath(_object.isForeign) - } + internal var isForeign: Bool { _slowPath(_object.isForeign) } @inlinable @inline(__always) internal func withFastUTF8( @@ -155,8 +141,8 @@ extension _StringGuts { range: Range, _ f: (UnsafeBufferPointer) throws -> R ) rethrows -> R { - return try self.withFastUTF8 { wholeUTF8 in - return try f(UnsafeBufferPointer(rebasing: wholeUTF8[range])) + try self.withFastUTF8 { wholeUTF8 in + try f(UnsafeBufferPointer(rebasing: wholeUTF8[range])) } } @@ -164,7 +150,7 @@ extension _StringGuts { internal func withFastCChar( _ f: (UnsafeBufferPointer) throws -> R ) rethrows -> R { - return try self.withFastUTF8 { utf8 in + try self.withFastUTF8 { utf8 in let ptr = utf8.baseAddress._unsafelyUnwrappedUnchecked._asCChar return try f(UnsafeBufferPointer(start: ptr, count: utf8.count)) } @@ -267,33 +253,25 @@ extension _StringGuts { internal typealias Index = String.Index @inlinable @inline(__always) - internal var startIndex: String.Index { - return Index(_encodedOffset: 0) - } + internal var startIndex: String.Index { Index(_encodedOffset: 0) } @inlinable @inline(__always) - internal var endIndex: String.Index { - return Index(_encodedOffset: self.count) - } + internal var endIndex: String.Index { Index(_encodedOffset: self.count) } } // Old SPI(corelibs-foundation) extension _StringGuts { @available(*, deprecated) public // SPI(corelibs-foundation) - var _isContiguousASCII: Bool { - return !isSmall && isFastUTF8 && isASCII - } + var _isContiguousASCII: Bool { !isSmall && isFastUTF8 && isASCII } @available(*, deprecated) public // SPI(corelibs-foundation) - var _isContiguousUTF16: Bool { - return false - } + var _isContiguousUTF16: Bool { false } // FIXME: Remove. Still used by swift-corelibs-foundation @available(*, deprecated) public var startASCII: UnsafeMutablePointer { - return UnsafeMutablePointer(mutating: _object.fastUTF8.baseAddress!) + UnsafeMutablePointer(mutating: _object.fastUTF8.baseAddress!) } // FIXME: Remove. Still used by swift-corelibs-foundation diff --git a/stdlib/public/core/StringGutsSlice.swift b/stdlib/public/core/StringGutsSlice.swift index 614c294b3a0fa..1d1df1bf3d49b 100644 --- a/stdlib/public/core/StringGutsSlice.swift +++ b/stdlib/public/core/StringGutsSlice.swift @@ -33,57 +33,43 @@ internal struct _StringGutsSlice { self._offsetRange = offsetRange } - @inlinable - internal var start: Int { - @inline(__always) get { return _offsetRange.lowerBound } - } - @inlinable - internal var end: Int { - @inline(__always) get { return _offsetRange.upperBound } - } + @inlinable @inline(__always) + internal var start: Int { _offsetRange.lowerBound } - @inlinable - internal var count: Int { - @inline(__always) get { return _offsetRange.count } - } + @inlinable @inline(__always) + internal var end: Int { _offsetRange.upperBound } - @inlinable - internal var isNFCFastUTF8: Bool { - @inline(__always) get { return _guts.isNFCFastUTF8 } - } + @inlinable @inline(__always) + internal var count: Int { _offsetRange.count } - @inlinable - internal var isASCII: Bool { - @inline(__always) get { return _guts.isASCII } - } + @inlinable @inline(__always) + internal var isNFCFastUTF8: Bool { _guts.isNFCFastUTF8 } - @inlinable - internal var isFastUTF8: Bool { - @inline(__always) get { return _guts.isFastUTF8 } - } + @inlinable @inline(__always) + internal var isASCII: Bool { _guts.isASCII } + + @inlinable @inline(__always) + internal var isFastUTF8: Bool { _guts.isFastUTF8 } + @inline(__always) internal var utf8Count: Int { - @inline(__always) get { - if _fastPath(self.isFastUTF8) { - return _offsetRange.count - } - return Substring(self).utf8.count + if _fastPath(self.isFastUTF8) { + return _offsetRange.count } + return Substring(self).utf8.count } - @inlinable + @inlinable @inline(__always) internal var range: Range { - @inline(__always) get { - return String.Index(_encodedOffset: _offsetRange.lowerBound) - ..< String.Index(_encodedOffset: _offsetRange.upperBound) - } + String.Index(_encodedOffset: _offsetRange.lowerBound) + ..< String.Index(_encodedOffset: _offsetRange.upperBound) } @inline(__always) internal func withFastUTF8( _ f: (UnsafeBufferPointer) throws -> R ) rethrows -> R { - return try _guts.withFastUTF8(range: _offsetRange, f) + try _guts.withFastUTF8(range: _offsetRange, f) } @_effects(releasenone) @@ -91,7 +77,7 @@ internal struct _StringGutsSlice { startingAt idx: String.Index ) -> (Unicode.Scalar, scalarLength: Int) { let (scalar, len) = _guts.foreignErrorCorrectedScalar(startingAt: idx) - if _slowPath(idx.encoded(offsetBy: len) > range.upperBound) { + if _slowPath(idx.encoded(offsetBy: len) > range.upperBound) { return (Unicode.Scalar._replacementCharacter, 1) } return (scalar, len) diff --git a/stdlib/public/core/StringIndex.swift b/stdlib/public/core/StringIndex.swift index 78dbb7e72e31b..9edb67720835c 100644 --- a/stdlib/public/core/StringIndex.swift +++ b/stdlib/public/core/StringIndex.swift @@ -50,16 +50,16 @@ extension String { extension String.Index { @inlinable @inline(__always) - internal var orderingValue: UInt64 { return _rawBits &>> 14 } + internal var orderingValue: UInt64 { _rawBits &>> 14 } // Whether this is at the canonical "start" position, that is encoded AND // transcoded offset of 0. @inlinable @inline(__always) - internal var isZeroPosition: Bool { return orderingValue == 0 } + internal var isZeroPosition: Bool { orderingValue == 0 } /// The UTF-16 code unit offset corresponding to this Index public func utf16Offset(in s: S) -> Int { - return s.utf16.distance(from: s.utf16.startIndex, to: self) + s.utf16.distance(from: s.utf16.startIndex, to: self) } /// The offset into a string's code units for this index. @@ -68,16 +68,14 @@ extension String.Index { Use utf16Offset(in:) to achieve the same behavior. """) @inlinable - public var encodedOffset: Int { return _encodedOffset } + public var encodedOffset: Int { _encodedOffset } @inlinable @inline(__always) - internal var _encodedOffset: Int { - return Int(truncatingIfNeeded: _rawBits &>> 16) - } + internal var _encodedOffset: Int { Int(truncatingIfNeeded: _rawBits &>> 16) } @inlinable @inline(__always) internal var transcodedOffset: Int { - return Int(truncatingIfNeeded: orderingValue & 0x3) + Int(truncatingIfNeeded: orderingValue & 0x3) } @usableFromInline @@ -159,7 +157,7 @@ extension String.Index { extension String.Index { @inlinable @inline(__always) internal var strippingTranscoding: String.Index { - return String.Index(_encodedOffset: self._encodedOffset) + String.Index(_encodedOffset: self._encodedOffset) } @inlinable @inline(__always) @@ -176,14 +174,14 @@ extension String.Index { @inlinable @inline(__always) internal var nextTranscoded: String.Index { - return String.Index( + String.Index( encodedOffset: self._encodedOffset, transcodedOffset: self.transcodedOffset &+ 1) } @inlinable @inline(__always) internal var priorTranscoded: String.Index { - return String.Index( + String.Index( encodedOffset: self._encodedOffset, transcodedOffset: self.transcodedOffset &- 1) } @@ -192,7 +190,7 @@ extension String.Index { // Note: strips any transcoded offset. @inlinable @inline(__always) internal func encoded(offsetBy n: Int) -> String.Index { - return String.Index(_encodedOffset: self._encodedOffset &+ n) + String.Index(_encodedOffset: self._encodedOffset &+ n) } @inlinable @inline(__always) @@ -206,14 +204,14 @@ extension String.Index { extension String.Index: Equatable { @inlinable @inline(__always) public static func == (lhs: String.Index, rhs: String.Index) -> Bool { - return lhs.orderingValue == rhs.orderingValue + lhs.orderingValue == rhs.orderingValue } } extension String.Index: Comparable { @inlinable @inline(__always) public static func < (lhs: String.Index, rhs: String.Index) -> Bool { - return lhs.orderingValue < rhs.orderingValue + lhs.orderingValue < rhs.orderingValue } } diff --git a/stdlib/public/core/StringIndexConversions.swift b/stdlib/public/core/StringIndexConversions.swift index dfb5c351d8534..7e7dfad0a82d1 100644 --- a/stdlib/public/core/StringIndexConversions.swift +++ b/stdlib/public/core/StringIndexConversions.swift @@ -133,7 +133,7 @@ extension String.Index { public func samePosition( in utf8: String.UTF8View ) -> String.UTF8View.Index? { - return String.UTF8View.Index(self, within: utf8) + String.UTF8View.Index(self, within: utf8) } /// Returns the position in the given UTF-16 view that corresponds exactly to @@ -161,7 +161,7 @@ extension String.Index { public func samePosition( in utf16: String.UTF16View ) -> String.UTF16View.Index? { - return String.UTF16View.Index(self, within: utf16) + String.UTF16View.Index(self, within: utf16) } } diff --git a/stdlib/public/core/StringInterpolation.swift b/stdlib/public/core/StringInterpolation.swift index 562ab84b487c9..1cff1a2d58388 100644 --- a/stdlib/public/core/StringInterpolation.swift +++ b/stdlib/public/core/StringInterpolation.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// /// Represents a string literal with interpolations while it is being built up. -/// +/// /// Do not create an instance of this type directly. It is used by the compiler /// when you create a string using string interpolation. Instead, use string /// interpolation to create a new string by including values, literals, @@ -26,7 +26,7 @@ /// """ /// print(message) /// // Prints "If one cookie costs 2 dollars, 3 cookies cost 6 dollars." -/// +/// /// When implementing an `ExpressibleByStringInterpolation` conformance, /// set the `StringInterpolation` associated type to /// `DefaultStringInterpolation` to get the same interpolation behavior as @@ -34,15 +34,15 @@ /// If you don't want the default behavior or don't want to construct a /// `String`, use a custom type conforming to `StringInterpolationProtocol` /// instead. -/// +/// /// Extending default string interpolation behavior /// =============================================== -/// +/// /// Code outside the standard library can extend string interpolation on /// `String` and many other common types by extending /// `DefaultStringInterpolation` and adding an `appendInterpolation(...)` /// method. For example: -/// +/// /// extension DefaultStringInterpolation { /// fileprivate mutating func appendInterpolation( /// escaped value: String, asASCII forceASCII: Bool = false) { @@ -51,12 +51,12 @@ /// } /// } /// } -/// +/// /// print("Escaped string: \(escaped: string)") -/// +/// /// See `StringInterpolationProtocol` for details on `appendInterpolation` /// methods. -/// +/// /// `DefaultStringInterpolation` extensions should add only `mutating` members /// and should not copy `self` or capture it in an escaping closure. @_fixed_layout @@ -64,10 +64,10 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol { /// The string contents accumulated by this instance. @usableFromInline internal var _storage: String - + /// Creates a string interpolation with storage pre-sized for a literal /// with the indicated attributes. - /// + /// /// Do not call this initializer directly. It is used by the compiler when /// interpreting string interpolations. @inlinable @@ -77,19 +77,19 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol { interpolationCount * capacityPerInterpolation _storage = String(_StringGuts(_initialCapacity: initialCapacity)) } - + /// Appends a literal segment of a string interpolation. - /// + /// /// Do not call this method directly. It is used by the compiler when /// interpreting string interpolations. @inlinable public mutating func appendLiteral(_ literal: String) { literal.write(to: &self) } - + /// Interpolates the given value's textual representation into the /// string literal being created. - /// + /// /// Do not call this method directly. It is used by the compiler when /// interpreting string interpolations. Instead, use string /// interpolation to create a new string by including values, literals, @@ -110,10 +110,10 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol { { value.write(to: &self) } - + /// Interpolates the given value's textual representation into the /// string literal being created. - /// + /// /// Do not call this method directly. It is used by the compiler when /// interpreting string interpolations. Instead, use string /// interpolation to create a new string by including values, literals, @@ -132,10 +132,10 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol { { value.write(to: &self) } - + /// Interpolates the given value's textual representation into the /// string literal being created. - /// + /// /// Do not call this method directly. It is used by the compiler when /// interpreting string interpolations. Instead, use string /// interpolation to create a new string by including values, literals, @@ -156,10 +156,10 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol { { value.description.write(to: &self) } - + /// Interpolates the given value's textual representation into the /// string literal being created. - /// + /// /// Do not call this method directly. It is used by the compiler when /// interpreting string interpolations. Instead, use string /// interpolation to create a new string by including values, literals, @@ -178,20 +178,16 @@ public struct DefaultStringInterpolation: StringInterpolationProtocol { public mutating func appendInterpolation(_ value: T) { _print_unlocked(value, &self) } - + /// Creates a string from this instance, consuming the instance in the /// process. @inlinable - internal __consuming func make() -> String { - return _storage - } + internal __consuming func make() -> String { _storage } } extension DefaultStringInterpolation: CustomStringConvertible { @inlinable - public var description: String { - return _storage - } + public var description: String { _storage } } extension DefaultStringInterpolation: TextOutputStream { @@ -199,7 +195,7 @@ extension DefaultStringInterpolation: TextOutputStream { public mutating func write(_ string: String) { _storage.append(string) } - + public mutating func _writeASCII(_ buffer: UnsafeBufferPointer) { _storage._guts.append(_StringGuts(buffer, isASCII: true)) } @@ -209,7 +205,7 @@ extension DefaultStringInterpolation: TextOutputStream { // default implementation. extension String { /// Creates a new instance from an interpolated string literal. - /// + /// /// Do not call this initializer directly. It is used by the compiler when /// you create a string using string interpolation. Instead, use string /// interpolation to create a new string by including values, literals, @@ -233,7 +229,7 @@ extension String { extension Substring { /// Creates a new instance from an interpolated string literal. - /// + /// /// Do not call this initializer directly. It is used by the compiler when /// you create a string using string interpolation. Instead, use string /// interpolation to create a new string by including values, literals, diff --git a/stdlib/public/core/StringLegacy.swift b/stdlib/public/core/StringLegacy.swift index e4ab13747bde3..df8d306f07b4b 100644 --- a/stdlib/public/core/StringLegacy.swift +++ b/stdlib/public/core/StringLegacy.swift @@ -44,10 +44,8 @@ extension String { } /// A Boolean value indicating whether a string has no characters. - @inlinable - public var isEmpty: Bool { - @inline(__always) get { return _guts.isEmpty } - } + @inlinable @inline(__always) + public var isEmpty: Bool { _guts.isEmpty } } extension StringProtocol { @@ -82,7 +80,7 @@ extension StringProtocol { /// - Returns: `true` if the string begins with `prefix`; otherwise, `false`. @inlinable public func hasPrefix(_ prefix: Prefix) -> Bool { - return self.starts(with: prefix) + self.starts(with: prefix) } /// Returns a Boolean value indicating whether the string ends with the @@ -116,7 +114,7 @@ extension StringProtocol { /// - Returns: `true` if the string ends with `suffix`; otherwise, `false`. @inlinable public func hasSuffix(_ suffix: Suffix) -> Bool { - return self.reversed().starts(with: suffix.reversed()) + self.reversed().starts(with: suffix.reversed()) } } diff --git a/stdlib/public/core/StringNormalization.swift b/stdlib/public/core/StringNormalization.swift index c50285baf1df8..9a654f9c74b1a 100644 --- a/stdlib/public/core/StringNormalization.swift +++ b/stdlib/public/core/StringNormalization.swift @@ -46,7 +46,7 @@ private func _unsafeMutableBufferPointerCast( _ count: Int, to: U.Type = U.self ) -> UnsafeMutableBufferPointer { - return UnsafeMutableBufferPointer( + UnsafeMutableBufferPointer( start: UnsafeMutableRawPointer(ptr).assumingMemoryBound(to: U.self), count: count ) @@ -57,7 +57,7 @@ private func _unsafeBufferPointerCast( _ count: Int, to: U.Type = U.self ) -> UnsafeBufferPointer { - return UnsafeBufferPointer( + UnsafeBufferPointer( start: UnsafeRawPointer(ptr).assumingMemoryBound(to: U.self), count: count ) @@ -155,7 +155,7 @@ extension Unicode.Scalar { // Quick check if a scalar is NFC and a segment starter internal var _isNFCStarter: Bool { // Otherwise, consult the properties - return self._hasNormalizationBoundaryBefore && self._isNFCQCYes + self._hasNormalizationBoundaryBefore && self._isNFCQCYes } } @@ -167,7 +167,6 @@ extension UnsafeBufferPointer where Element == UInt8 { } return !UTF8.isContinuation(self[index]) } - } //If this returns nil, it means the outputBuffer ran out of space @@ -176,7 +175,7 @@ internal func _tryNormalize( into outputBuffer: UnsafeMutablePointer<_Normalization._SegmentOutputBuffer> ) -> Int? { - return _tryNormalize(input, into: _castOutputBuffer(outputBuffer)) + _tryNormalize(input, into: _castOutputBuffer(outputBuffer)) } //If this returns nil, it means the outputBuffer ran out of space @@ -213,7 +212,7 @@ private func fastFill( _ outputBuffer: UnsafeMutableBufferPointer ) -> (read: Int, written: Int)? { let outputBufferThreshold = outputBuffer.count - 4 - + // TODO: Additional fast-path: All CCC-ascending NFC_QC segments are NFC // TODO: Just freakin do normalization and don't bother with ICU var outputCount = 0 @@ -261,9 +260,9 @@ private func copyUTF16Segment( if scalar._hasNormalizationBoundaryBefore && readIndex != range.lowerBound { break } - + readIndex += length - + for cu in scalar.utf16 { if outputWriteIndex < outputCount { outputBuffer[outputWriteIndex] = cu @@ -286,14 +285,14 @@ private func transcodeValidUTF16ToUTF8( var writeIndex = 0 let outputCount = outputBuffer.count let sourceCount = sourceBuffer.count - + while readIndex < sourceCount { let (scalar, length) = _decodeScalar(sourceBuffer, startingAt: readIndex) //we don't need to check for normalization boundaries here because we are only transcoding //a single segment at this point - + readIndex += length - + for cu in UTF8.encode(scalar)._unsafelyUnwrappedUnchecked { if writeIndex < outputCount { outputBuffer[writeIndex] = cu @@ -323,7 +322,7 @@ internal func _allocateBuffers( let newOutputBuffer = UnsafeMutableBufferPointer.allocate(capacity: output) let newICUInputBuffer = UnsafeMutableBufferPointer.allocate(capacity: icuInput) let newICUOutputBuffer = UnsafeMutableBufferPointer.allocate(capacity: icuOutput) - + switch bufferToCopy { case .none: break @@ -337,7 +336,7 @@ internal func _allocateBuffers( let (_, written) = newICUOutputBuffer.initialize(from: icuOutputBuffer) _internalInvariant(written == 16) } - + outputBuffer = newOutputBuffer icuInputBuffer = newICUInputBuffer icuOutputBuffer = newICUOutputBuffer @@ -355,7 +354,7 @@ internal func _fastNormalize( if let (read, filled) = fastFill(rebasedSourceBuffer, outputBuffer) { let nextIndex = readIndex.encoded(offsetBy: read) _internalInvariant(sourceBuffer.isOnUnicodeScalarBoundary(nextIndex._encodedOffset)) - + return NormalizationResult( amountFilled: filled, nextReadPosition: nextIndex, allocatedBuffers: false) } @@ -376,21 +375,21 @@ internal func _fastNormalize( allocatedBuffers = true return f()! } - + let (read, filled) = performWithAllocationIfNecessary(preserving: .none) { () -> (Int, Int)? in return copyUTF16Segment(boundedBy: 0.. Int? in return _tryNormalize( UnsafeBufferPointer(rebasing: icuInputBuffer[.. Int? in return transcodeValidUTF16ToUTF8( UnsafeBufferPointer(rebasing: icuOutputBuffer[.. Int? in return _tryNormalize( UnsafeBufferPointer(rebasing: icuInputBuffer[.. Int? in return transcodeValidUTF16ToUTF8( UnsafeBufferPointer(rebasing: icuOutputBuffer[.. UInt64 { - return isASCII ? 0xE000_0000_0000_0000 : 0xA000_0000_0000_0000 + isASCII ? 0xE000_0000_0000_0000 : 0xA000_0000_0000_0000 } // Discriminator for small strings @@ -371,16 +369,14 @@ extension _StringObject.Nibbles { // Discriminator for large, immortal, swift-native strings @inlinable @inline(__always) - internal static func largeImmortal() -> UInt64 { - return 0x8000_0000_0000_0000 - } + internal static func largeImmortal() -> UInt64 { 0x8000_0000_0000_0000 } // Discriminator for large, mortal (i.e. managed), swift-native strings @inlinable @inline(__always) - internal static func largeMortal() -> UInt64 { return 0x0000_0000_0000_0000 } + internal static func largeMortal() -> UInt64 { 0x0000_0000_0000_0000 } internal static func largeCocoa(providesFastUTF8: Bool) -> UInt64 { - return providesFastUTF8 ? 0x4000_0000_0000_0000 : 0x5000_0000_0000_0000 + providesFastUTF8 ? 0x4000_0000_0000_0000 : 0x5000_0000_0000_0000 } } @@ -396,19 +392,19 @@ extension _StringObject { @inlinable @inline(__always) internal var isImmortal: Bool { - return (discriminatedObjectRawBits & 0x8000_0000_0000_0000) != 0 + (discriminatedObjectRawBits & 0x8000_0000_0000_0000) != 0 } @inlinable @inline(__always) - internal var isMortal: Bool { return !isImmortal } + internal var isMortal: Bool { !isImmortal } @inlinable @inline(__always) internal var isSmall: Bool { - return (discriminatedObjectRawBits & 0x2000_0000_0000_0000) != 0 + (discriminatedObjectRawBits & 0x2000_0000_0000_0000) != 0 } @inlinable @inline(__always) - internal var isLarge: Bool { return !isSmall } + internal var isLarge: Bool { !isSmall } // Whether this string can provide access to contiguous UTF-8 code units: // - Small strings can by spilling to the stack @@ -418,17 +414,17 @@ extension _StringObject { // - Non-Cocoa shared strings @inlinable @inline(__always) internal var providesFastUTF8: Bool { - return (discriminatedObjectRawBits & 0x1000_0000_0000_0000) == 0 + (discriminatedObjectRawBits & 0x1000_0000_0000_0000) == 0 } @inlinable @inline(__always) - internal var isForeign: Bool { return !providesFastUTF8 } + internal var isForeign: Bool { !providesFastUTF8 } // Whether we are native or shared, i.e. we have a backing class which // conforms to `_AbstractStringStorage` @inline(__always) internal var hasStorage: Bool { - return (discriminatedObjectRawBits & 0xF000_0000_0000_0000) == 0 + (discriminatedObjectRawBits & 0xF000_0000_0000_0000) == 0 } // Whether we are a mortal, native (tail-allocated) string @@ -444,7 +440,7 @@ extension _StringObject { } // Whether we are a mortal, shared string (managed by Swift runtime) - internal var hasSharedStorage: Bool { return hasStorage && !hasNativeStorage } + internal var hasSharedStorage: Bool { hasStorage && !hasNativeStorage } } // Queries conditional on being in a large or fast form. @@ -459,7 +455,7 @@ extension _StringObject { // Whether this string is shared, presupposing it is both large and fast @inline(__always) - internal var largeFastIsShared: Bool { return !largeFastIsTailAllocated } + internal var largeFastIsShared: Bool { !largeFastIsTailAllocated } // Whether this string is a lazily-bridged NSString, presupposing it is large @inline(__always) @@ -473,7 +469,7 @@ extension _StringObject { @_alwaysEmitIntoClient @inline(__always) internal var isPreferredRepresentation: Bool { - return _fastPath(isSmall || _countAndFlags.isTailAllocated) + _fastPath(isSmall || _countAndFlags.isTailAllocated) } } @@ -534,7 +530,7 @@ extension _StringObject { @inlinable internal static func getSmallCount(fromRaw x: UInt64) -> Int { - return Int(truncatingIfNeeded: (x & 0x0F00_0000_0000_0000) &>> 56) + Int(truncatingIfNeeded: (x & 0x0F00_0000_0000_0000) &>> 56) } @inlinable @inline(__always) @@ -545,7 +541,7 @@ extension _StringObject { @inlinable internal static func getSmallIsASCII(fromRaw x: UInt64) -> Bool { - return x & 0x4000_0000_0000_0000 != 0 + x & 0x4000_0000_0000_0000 != 0 } @inlinable @inline(__always) internal var smallIsASCII: Bool { @@ -617,26 +613,22 @@ extension _StringObject { */ extension _StringObject.CountAndFlags { @inlinable @inline(__always) - internal static var countMask: UInt64 { return 0x0000_FFFF_FFFF_FFFF } + internal static var countMask: UInt64 { 0x0000_FFFF_FFFF_FFFF } @inlinable @inline(__always) - internal static var flagsMask: UInt64 { return ~countMask } + internal static var flagsMask: UInt64 { ~countMask } @inlinable @inline(__always) - internal static var isASCIIMask: UInt64 { return 0x8000_0000_0000_0000 } + internal static var isASCIIMask: UInt64 { 0x8000_0000_0000_0000 } @inlinable @inline(__always) - internal static var isNFCMask: UInt64 { return 0x4000_0000_0000_0000 } + internal static var isNFCMask: UInt64 { 0x4000_0000_0000_0000 } @inlinable @inline(__always) - internal static var isNativelyStoredMask: UInt64 { - return 0x2000_0000_0000_0000 - } + internal static var isNativelyStoredMask: UInt64 { 0x2000_0000_0000_0000 } @inlinable @inline(__always) - internal static var isTailAllocatedMask: UInt64 { - return 0x1000_0000_0000_0000 - } + internal static var isTailAllocatedMask: UInt64 { 0x1000_0000_0000_0000 } // General purpose bottom initializer @inlinable @inline(__always) @@ -724,30 +716,28 @@ extension _StringObject.CountAndFlags { @inlinable @inline(__always) internal var count: Int { - return Int( + Int( truncatingIfNeeded: _storage & _StringObject.CountAndFlags.countMask) } @inlinable @inline(__always) - internal var flags: UInt16 { - return UInt16(truncatingIfNeeded: _storage &>> 48) - } + internal var flags: UInt16 { UInt16(truncatingIfNeeded: _storage &>> 48) } @inlinable @inline(__always) internal var isASCII: Bool { - return 0 != _storage & _StringObject.CountAndFlags.isASCIIMask + 0 != _storage & _StringObject.CountAndFlags.isASCIIMask } @inlinable @inline(__always) internal var isNFC: Bool { - return 0 != _storage & _StringObject.CountAndFlags.isNFCMask + 0 != _storage & _StringObject.CountAndFlags.isNFCMask } @inlinable @inline(__always) internal var isNativelyStored: Bool { - return 0 != _storage & _StringObject.CountAndFlags.isNativelyStoredMask + 0 != _storage & _StringObject.CountAndFlags.isNativelyStoredMask } @inlinable @inline(__always) internal var isTailAllocated: Bool { - return 0 != _storage & _StringObject.CountAndFlags.isTailAllocatedMask + 0 != _storage & _StringObject.CountAndFlags.isTailAllocatedMask } #if !INTERNAL_CHECKS_ENABLED @@ -864,7 +854,7 @@ extension _StringObject { // // TODO(String micro-performance): Check generated code @inlinable @inline(__always) - internal var count: Int { return isSmall ? smallCount : largeCount } + internal var count: Int { isSmall ? smallCount : largeCount } // // Whether the string is all ASCII @@ -902,7 +892,7 @@ extension _StringObject { internal var hasObjCBridgeableObject: Bool { @_effects(releasenone) get { // Currently, all mortal objects can zero-cost bridge - return !self.isImmortal + !self.isImmortal } } diff --git a/stdlib/public/core/StringProtocol.swift b/stdlib/public/core/StringProtocol.swift index 2b2f3fdd15290..6998f7dac0d28 100644 --- a/stdlib/public/core/StringProtocol.swift +++ b/stdlib/public/core/StringProtocol.swift @@ -129,7 +129,7 @@ extension StringProtocol { var _ephemeralString: String { @_specialize(where Self == String) @_specialize(where Self == Substring) - get { return String(self) } + get { String(self) } } internal var _gutsSlice: _StringGutsSlice { @@ -146,15 +146,12 @@ extension StringProtocol { } } - @inlinable + @inlinable @inline(__always) internal var _offsetRange: Range { - @inline(__always) get { - let start = startIndex - let end = endIndex - _internalInvariant( - start.transcodedOffset == 0 && end.transcodedOffset == 0) - return Range(uncheckedBounds: (start._encodedOffset, end._encodedOffset)) - } + let (start, end) = (startIndex, endIndex) + _internalInvariant( + start.transcodedOffset == 0 && end.transcodedOffset == 0) + return Range(uncheckedBounds: (start._encodedOffset, end._encodedOffset)) } @inlinable @@ -183,7 +180,7 @@ extension String { /// Contiguous strings also benefit from fast-paths and better optimizations. /// @_alwaysEmitIntoClient - public var isContiguousUTF8: Bool { return _guts.isFastUTF8 } + public var isContiguousUTF8: Bool { _guts.isFastUTF8 } /// If this string is not contiguous, make it so. If this mutates the string, /// it will invalidate any pre-existing indices. @@ -228,7 +225,7 @@ extension Substring { /// Contiguous strings also benefit from fast-paths and better optimizations. /// @_alwaysEmitIntoClient - public var isContiguousUTF8: Bool { return self.base.isContiguousUTF8 } + public var isContiguousUTF8: Bool { self.base.isContiguousUTF8 } /// If this string is not contiguous, make it so. If this mutates the /// substring, it will invalidate any pre-existing indices. diff --git a/stdlib/public/core/StringRangeReplaceableCollection.swift b/stdlib/public/core/StringRangeReplaceableCollection.swift index 67407aca2b6fe..f4955e448a7a0 100644 --- a/stdlib/public/core/StringRangeReplaceableCollection.swift +++ b/stdlib/public/core/StringRangeReplaceableCollection.swift @@ -325,14 +325,14 @@ extension String { // source compatibility issues when String becomes a collection @_transparent public func max(_ x: T, _ y: T) -> T { - return Swift.max(x,y) + Swift.max(x,y) } // This is needed because of the issue described in SR-4660 which causes // source compatibility issues when String becomes a collection @_transparent public func min(_ x: T, _ y: T) -> T { - return Swift.min(x,y) + Swift.min(x,y) } } diff --git a/stdlib/public/core/StringStorage.swift b/stdlib/public/core/StringStorage.swift index e608e0d248210..dd2b039641080 100644 --- a/stdlib/public/core/StringStorage.swift +++ b/stdlib/public/core/StringStorage.swift @@ -29,7 +29,7 @@ internal let _cocoaUTF8Encoding:UInt = 4 /* NSUTF8StringEncoding */ @_effects(readonly) private func _isNSString(_ str:AnyObject) -> UInt8 { - return _swift_stdlib_isNSString(str) + _swift_stdlib_isNSString(str) } #else @@ -143,9 +143,9 @@ extension _AbstractStringStorage { // one of ours. defer { _fixLifetime(other) } - + let otherUTF16Length = _stdlib_binary_CFStringGetLength(other) - + // CFString will only give us ASCII bytes here, but that's fine. // We already handled non-ASCII UTF8 strings earlier since they're Swift. if let otherStart = _cocoaUTF8Pointer(other) { @@ -156,11 +156,11 @@ extension _AbstractStringStorage { return (start == otherStart || (memcmp(start, otherStart, count) == 0)) ? 1 : 0 } - + if UTF16Length != otherUTF16Length { return 0 } - + /* The abstract implementation of -isEqualToString: falls back to -compare: immediately, so when we run out of fast options to try, do the same. @@ -195,11 +195,11 @@ final internal class __StringStorage internal var _reserved: UInt16 @inline(__always) - internal var count: Int { return _count } + internal var count: Int { _count } @inline(__always) internal var _countAndFlags: _StringObject.CountAndFlags { - return CountAndFlags(count: _count, flags: _flags) + CountAndFlags(count: _count, flags: _flags) } #else // The capacity of our allocation. Note that this includes the nul-terminator, @@ -208,23 +208,23 @@ final internal class __StringStorage internal var _countAndFlags: _StringObject.CountAndFlags @inline(__always) - internal var count: Int { return _countAndFlags.count } + internal var count: Int { _countAndFlags.count } // The total allocated storage capacity. Note that this includes the required // nul-terminator. @inline(__always) internal var _realCapacity: Int { - return Int(truncatingIfNeeded: + Int(truncatingIfNeeded: _realCapacityAndFlags & CountAndFlags.countMask) } #endif @inline(__always) - final internal var isASCII: Bool { return _countAndFlags.isASCII } + final internal var isASCII: Bool { _countAndFlags.isASCII } final internal var asString: String { @_effects(readonly) @inline(__always) get { - return String(_StringGuts(self)) + String(_StringGuts(self)) } } @@ -233,7 +233,7 @@ final internal class __StringStorage @objc(length) final internal var UTF16Length: Int { @_effects(readonly) @inline(__always) get { - return asString.utf16.count // UTF16View special-cases ASCII for us. + asString.utf16.count // UTF16View special-cases ASCII for us. } } @@ -275,14 +275,12 @@ final internal class __StringStorage @objc(UTF8String) @_effects(readonly) - final internal func _utf8String() -> UnsafePointer? { - return start - } + final internal func _utf8String() -> UnsafePointer? { start } @objc(cStringUsingEncoding:) @_effects(readonly) final internal func cString(encoding: UInt) -> UnsafePointer? { - return _cString(encoding: encoding) + _cString(encoding: encoding) } @objc(getCString:maxLength:encoding:) @@ -290,7 +288,7 @@ final internal class __StringStorage final internal func getCString( _ outputPtr: UnsafeMutablePointer, maxLength: Int, encoding: UInt ) -> Int8 { - return _getCString(outputPtr, maxLength, encoding) + _getCString(outputPtr, maxLength, encoding) } @objc @@ -306,7 +304,7 @@ final internal class __StringStorage @objc(isEqualToString:) @_effects(readonly) final internal func isEqual(to other: AnyObject?) -> Int8 { - return _isEqual(other) + _isEqual(other) } @objc(copyWithZone:) @@ -315,7 +313,7 @@ final internal class __StringStorage // mutations may only occur when instances are uniquely referenced. // Therefore, it is safe to return self here; any outstanding Objective-C // reference will make the instance non-unique. - return self + self } #endif // _runtime(_ObjC) @@ -431,32 +429,24 @@ extension __StringStorage { extension __StringStorage { @inline(__always) private var mutableStart: UnsafeMutablePointer { - return UnsafeMutablePointer(Builtin.projectTailElems(self, UInt8.self)) + UnsafeMutablePointer(Builtin.projectTailElems(self, UInt8.self)) } @inline(__always) - private var mutableEnd: UnsafeMutablePointer { - return mutableStart + count - } + private var mutableEnd: UnsafeMutablePointer { mutableStart + count } @inline(__always) - internal var start: UnsafePointer { - return UnsafePointer(mutableStart) - } + internal var start: UnsafePointer { UnsafePointer(mutableStart) } @inline(__always) - private final var end: UnsafePointer { - return UnsafePointer(mutableEnd) - } + private final var end: UnsafePointer { UnsafePointer(mutableEnd) } // Point to the nul-terminator. @inline(__always) - private final var terminator: UnsafeMutablePointer { - return mutableEnd - } + private final var terminator: UnsafeMutablePointer { mutableEnd } @inline(__always) private var codeUnits: UnsafeBufferPointer { - return UnsafeBufferPointer(start: start, count: count) + UnsafeBufferPointer(start: start, count: count) } // @opaque @@ -471,9 +461,7 @@ extension __StringStorage { // The total capacity available for code units. Note that this excludes the // required nul-terminator. - internal var capacity: Int { - return _realCapacity &- 1 - } + internal var capacity: Int { _realCapacity &- 1 } // The unused capacity available for appending. Note that this excludes the // required nul-terminator. @@ -481,13 +469,13 @@ extension __StringStorage { // NOTE: Callers who wish to mutate this storage should enfore nul-termination @inline(__always) private var unusedStorage: UnsafeMutableBufferPointer { - return UnsafeMutableBufferPointer( + UnsafeMutableBufferPointer( start: mutableEnd, count: unusedCapacity) } // The capacity available for appending. Note that this excludes the required // nul-terminator. - internal var unusedCapacity: Int { return _realCapacity &- count &- 1 } + internal var unusedCapacity: Int { _realCapacity &- count &- 1 } #if !INTERNAL_CHECKS_ENABLED @inline(__always) internal func _invariantCheck() {} @@ -673,7 +661,7 @@ final internal class __SharedStringStorage @inline(__always) internal var _countAndFlags: _StringObject.CountAndFlags { - return CountAndFlags(count: _count, flags: _flags) + CountAndFlags(count: _count, flags: _flags) } #else internal var _countAndFlags: _StringObject.CountAndFlags @@ -681,7 +669,7 @@ final internal class __SharedStringStorage internal var _breadcrumbs: _StringBreadcrumbs? = nil - internal var count: Int { return _countAndFlags.count } + internal var count: Int { _countAndFlags.count } internal init( immortal ptr: UnsafePointer, @@ -700,11 +688,11 @@ final internal class __SharedStringStorage } @inline(__always) - final internal var isASCII: Bool { return _countAndFlags.isASCII } + final internal var isASCII: Bool { _countAndFlags.isASCII } final internal var asString: String { @_effects(readonly) @inline(__always) get { - return String(_StringGuts(self)) + String(_StringGuts(self)) } } @@ -713,7 +701,7 @@ final internal class __SharedStringStorage @objc(length) final internal var UTF16Length: Int { @_effects(readonly) get { - return asString.utf16.count // UTF16View special-cases ASCII for us. + asString.utf16.count // UTF16View special-cases ASCII for us. } } @@ -765,14 +753,12 @@ final internal class __SharedStringStorage @objc(UTF8String) @_effects(readonly) - final internal func _utf8String() -> UnsafePointer? { - return start - } + final internal func _utf8String() -> UnsafePointer? { start } @objc(cStringUsingEncoding:) @_effects(readonly) final internal func cString(encoding: UInt) -> UnsafePointer? { - return _cString(encoding: encoding) + _cString(encoding: encoding) } @objc(getCString:maxLength:encoding:) @@ -780,14 +766,12 @@ final internal class __SharedStringStorage final internal func getCString( _ outputPtr: UnsafeMutablePointer, maxLength: Int, encoding: UInt ) -> Int8 { - return _getCString(outputPtr, maxLength, encoding) + _getCString(outputPtr, maxLength, encoding) } @objc(isEqualToString:) @_effects(readonly) - final internal func isEqual(to other:AnyObject?) -> Int8 { - return _isEqual(other) - } + final internal func isEqual(to other:AnyObject?) -> Int8 { _isEqual(other) } @objc(copyWithZone:) final internal func copy(with zone: _SwiftNSZone?) -> AnyObject { @@ -795,7 +779,7 @@ final internal class __SharedStringStorage // mutations may only occur when instances are uniquely referenced. // Therefore, it is safe to return self here; any outstanding Objective-C // reference will make the instance non-unique. - return self + self } #endif // _runtime(_ObjC) diff --git a/stdlib/public/core/StringTesting.swift b/stdlib/public/core/StringTesting.swift index dee9f7bf8cf18..2b78708274c32 100644 --- a/stdlib/public/core/StringTesting.swift +++ b/stdlib/public/core/StringTesting.swift @@ -38,7 +38,7 @@ struct _StringRepresentation { extension String { public // @testable - func _classify() -> _StringRepresentation { return _guts._classify() } + func _classify() -> _StringRepresentation { _guts._classify() } } extension _StringGuts { diff --git a/stdlib/public/core/StringUTF16View.swift b/stdlib/public/core/StringUTF16View.swift index 9e9ed6eae5c22..4b28e3d0ffd87 100644 --- a/stdlib/public/core/StringUTF16View.swift +++ b/stdlib/public/core/StringUTF16View.swift @@ -129,14 +129,14 @@ extension String.UTF16View: BidirectionalCollection { /// The position of the first code unit if the `String` is /// nonempty; identical to `endIndex` otherwise. @inlinable @inline(__always) - public var startIndex: Index { return _guts.startIndex } + public var startIndex: Index { _guts.startIndex } /// The "past the end" position---that is, the position one greater than /// the last valid subscript argument. /// /// In an empty UTF-16 view, `endIndex` is equal to `startIndex`. @inlinable @inline(__always) - public var endIndex: Index { return _guts.endIndex } + public var endIndex: Index { _guts.endIndex } @inlinable @inline(__always) public func index(after i: Index) -> Index { @@ -301,20 +301,18 @@ extension String.UTF16View { } } @inlinable - public __consuming func makeIterator() -> Iterator { - return Iterator(_guts) - } + public __consuming func makeIterator() -> Iterator { Iterator(_guts) } } extension String.UTF16View: CustomStringConvertible { @inlinable @inline(__always) - public var description: String { return String(_guts) } + public var description: String { String(_guts) } } extension String.UTF16View: CustomDebugStringConvertible { public var debugDescription: String { - return "StringUTF16(\(self.description.debugDescription))" + "StringUTF16(\(self.description.debugDescription))" } } @@ -322,7 +320,7 @@ extension String { /// A UTF-16 encoding of `self`. @inlinable public var utf16: UTF16View { - @inline(__always) get { return UTF16View(_guts) } + @inline(__always) get { UTF16View(_guts) } @inline(__always) set { self = String(newValue._guts) } } @@ -399,16 +397,14 @@ extension String.UTF16View.Index { public func samePosition( in unicodeScalars: String.UnicodeScalarView ) -> String.UnicodeScalarIndex? { - return String.UnicodeScalarIndex(self, within: unicodeScalars) + String.UnicodeScalarIndex(self, within: unicodeScalars) } } // Reflection extension String.UTF16View : CustomReflectable { /// Returns a mirror that reflects the UTF-16 view of a string. - public var customMirror: Mirror { - return Mirror(self, unlabeledChildren: self) - } + public var customMirror: Mirror { Mirror(self, unlabeledChildren: self) } } // Slicing @@ -416,7 +412,7 @@ extension String.UTF16View { public typealias SubSequence = Substring.UTF16View public subscript(r: Range) -> Substring.UTF16View { - return Substring.UTF16View(self, _bounds: r) + Substring.UTF16View(self, _bounds: r) } } @@ -493,7 +489,7 @@ extension String.Index { extension String.UTF16View { // A simple heuristic we can always tweak later. Not needed for correctness @inlinable @inline(__always) - internal var _shortHeuristic: Int { return 32 } + internal var _shortHeuristic: Int { 32 } @usableFromInline @_effects(releasenone) diff --git a/stdlib/public/core/StringUTF8View.swift b/stdlib/public/core/StringUTF8View.swift index c641a08cb0574..40804a77cda7c 100644 --- a/stdlib/public/core/StringUTF8View.swift +++ b/stdlib/public/core/StringUTF8View.swift @@ -122,14 +122,14 @@ extension String.UTF8View: BidirectionalCollection { /// /// If the UTF-8 view is empty, `startIndex` is equal to `endIndex`. @inlinable @inline(__always) - public var startIndex: Index { return _guts.startIndex } + public var startIndex: Index { _guts.startIndex } /// The "past the end" position---that is, the position one /// greater than the last valid subscript argument. /// /// In an empty UTF-8 view, `endIndex` is equal to `startIndex`. @inlinable @inline(__always) - public var endIndex: Index { return _guts.endIndex } + public var endIndex: Index { _guts.endIndex } /// Returns the next consecutive position after `i`. /// @@ -218,12 +218,12 @@ extension String.UTF8View: BidirectionalCollection { extension String.UTF8View: CustomStringConvertible { @inlinable @inline(__always) - public var description: String { return String(_guts) } + public var description: String { String(_guts) } } extension String.UTF8View: CustomDebugStringConvertible { public var debugDescription: String { - return "UTF8View(\(self.description.debugDescription))" + "UTF8View(\(self.description.debugDescription))" } } @@ -232,7 +232,7 @@ extension String { /// A UTF-8 encoding of `self`. @inlinable public var utf8: UTF8View { - @inline(__always) get { return UTF8View(self._guts) } + @inline(__always) get { UTF8View(self._guts) } set { self = String(newValue._guts) } } @@ -347,7 +347,7 @@ extension String.UTF8View.Index { extension String.UTF8View : CustomReflectable { /// Returns a mirror that reflects the UTF-8 view of a string. public var customMirror: Mirror { - return Mirror(self, unlabeledChildren: self) + Mirror(self, unlabeledChildren: self) } } @@ -365,7 +365,7 @@ extension String.UTF8View { @inlinable @available(swift, introduced: 4) public subscript(r: Range) -> String.UTF8View.SubSequence { - return Substring.UTF8View(self, _bounds: r) + Substring.UTF8View(self, _bounds: r) } } diff --git a/stdlib/public/core/StringUnicodeScalarView.swift b/stdlib/public/core/StringUnicodeScalarView.swift index 5a9a589bbd4c1..d0a4f9d2af728 100644 --- a/stdlib/public/core/StringUnicodeScalarView.swift +++ b/stdlib/public/core/StringUnicodeScalarView.swift @@ -92,14 +92,14 @@ extension String.UnicodeScalarView: BidirectionalCollection { /// /// If the string is empty, `startIndex` is equal to `endIndex`. @inlinable @inline(__always) - public var startIndex: Index { return _guts.startIndex } + public var startIndex: Index { _guts.startIndex } /// The "past the end" position---that is, the position one greater than /// the last valid subscript argument. /// /// In an empty Unicode scalars view, `endIndex` is equal to `startIndex`. @inlinable @inline(__always) - public var endIndex: Index { return _guts.endIndex } + public var endIndex: Index { _guts.endIndex } /// Returns the next consecutive location after `i`. /// @@ -127,7 +127,7 @@ extension String.UnicodeScalarView: BidirectionalCollection { if _fastPath(_guts.isFastUTF8) { let len = _guts.withFastUTF8 { utf8 -> Int in - return _utf8ScalarLength(utf8, endingAt: i._encodedOffset) + _utf8ScalarLength(utf8, endingAt: i._encodedOffset) } _internalInvariant(len <= 4, "invalid UTF8") return i.encoded(offsetBy: -len) @@ -189,19 +189,17 @@ extension String.UnicodeScalarView { } } @inlinable - public __consuming func makeIterator() -> Iterator { - return Iterator(_guts) - } + public __consuming func makeIterator() -> Iterator { Iterator(_guts) } } extension String.UnicodeScalarView: CustomStringConvertible { @inlinable @inline(__always) - public var description: String { return String(_guts) } + public var description: String { String(_guts) } } extension String.UnicodeScalarView: CustomDebugStringConvertible { public var debugDescription: String { - return "StringUnicodeScalarView(\(self.description.debugDescription))" + "StringUnicodeScalarView(\(self.description.debugDescription))" } } @@ -234,7 +232,7 @@ extension String { /// The string's value represented as a collection of Unicode scalar values. @inlinable public var unicodeScalars: UnicodeScalarView { - @inline(__always) get { return UnicodeScalarView(_guts) } + @inline(__always) get { UnicodeScalarView(_guts) } @inline(__always) set { _guts = newValue._guts } } } @@ -371,16 +369,14 @@ extension String.UnicodeScalarIndex { /// an attempt to convert the position of a UTF-8 continuation byte /// returns `nil`. public func samePosition(in characters: String) -> String.Index? { - return String.Index(self, within: characters) + String.Index(self, within: characters) } } // Reflection extension String.UnicodeScalarView : CustomReflectable { /// Returns a mirror that reflects the Unicode scalars view of a string. - public var customMirror: Mirror { - return Mirror(self, unlabeledChildren: self) - } + public var customMirror: Mirror { Mirror(self, unlabeledChildren: self) } } diff --git a/stdlib/public/core/Substring.swift b/stdlib/public/core/Substring.swift index 809a25dc08faa..bbb14a89199b6 100644 --- a/stdlib/public/core/Substring.swift +++ b/stdlib/public/core/Substring.swift @@ -118,10 +118,10 @@ public struct Substring { extension Substring { /// Returns the underlying string from which this Substring was derived. @_alwaysEmitIntoClient - public var base: String { return _slice.base } + public var base: String { _slice.base } @inlinable @inline(__always) - internal var _wholeGuts: _StringGuts { return base._guts } + internal var _wholeGuts: _StringGuts { base._guts } @inlinable internal var _offsetRange: Range { @@ -149,10 +149,10 @@ extension Substring: StringProtocol { public typealias SubSequence = Substring @inlinable @inline(__always) - public var startIndex: Index { return _slice.startIndex } + public var startIndex: Index { _slice.startIndex } @inlinable @inline(__always) - public var endIndex: Index { return _slice.endIndex } + public var endIndex: Index { _slice.endIndex } @inlinable @inline(__always) public func index(after i: Index) -> Index { @@ -191,12 +191,10 @@ extension Substring: StringProtocol { @inlinable @inline(__always) public func distance(from start: Index, to end: Index) -> Int { - return _slice.distance(from: start, to: end) + _slice.distance(from: start, to: end) } - public subscript(i: Index) -> Character { - return _slice[i] - } + public subscript(i: Index) -> Character { _slice[i] } public mutating func replaceSubrange( _ bounds: Range, @@ -271,7 +269,7 @@ extension Substring: StringProtocol { _ body: (UnsafePointer) throws -> Result) rethrows -> Result { // TODO(String performance): Detect when we cover the rest of a nul- // terminated String, and thus can avoid a copy. - return try String(self).withCString(body) + try String(self).withCString(body) } /// Calls the given closure with a pointer to the contents of the string, @@ -297,21 +295,21 @@ extension Substring: StringProtocol { ) rethrows -> Result { // TODO(String performance): Detect when we cover the rest of a nul- // terminated String, and thus can avoid a copy. - return try String(self).withCString(encodedAs: targetEncoding, body) + try String(self).withCString(encodedAs: targetEncoding, body) } } extension Substring : CustomReflectable { - public var customMirror: Mirror { return String(self).customMirror } + public var customMirror: Mirror { String(self).customMirror } } extension Substring : CustomStringConvertible { @inlinable @inline(__always) - public var description: String { return String(self) } + public var description: String { String(self) } } extension Substring : CustomDebugStringConvertible { - public var debugDescription: String { return String(self).debugDescription } + public var debugDescription: String { String(self).debugDescription } } extension Substring : LosslessStringConvertible { @@ -347,19 +345,19 @@ extension Substring.UTF8View : BidirectionalCollection { // Plumb slice operations through // @inlinable - public var startIndex: Index { return _slice.startIndex } + public var startIndex: Index { _slice.startIndex } @inlinable - public var endIndex: Index { return _slice.endIndex } + public var endIndex: Index { _slice.endIndex } @inlinable - public subscript(index: Index) -> Element { return _slice[index] } + public subscript(index: Index) -> Element { _slice[index] } @inlinable - public var indices: Indices { return _slice.indices } + public var indices: Indices { _slice.indices } @inlinable - public func index(after i: Index) -> Index { return _slice.index(after: i) } + public func index(after i: Index) -> Index { _slice.index(after: i) } @inlinable public func formIndex(after i: inout Index) { @@ -368,19 +366,19 @@ extension Substring.UTF8View : BidirectionalCollection { @inlinable public func index(_ i: Index, offsetBy n: Int) -> Index { - return _slice.index(i, offsetBy: n) + _slice.index(i, offsetBy: n) } @inlinable public func index( _ i: Index, offsetBy n: Int, limitedBy limit: Index ) -> Index? { - return _slice.index(i, offsetBy: n, limitedBy: limit) + _slice.index(i, offsetBy: n, limitedBy: limit) } @inlinable public func distance(from start: Index, to end: Index) -> Int { - return _slice.distance(from: start, to: end) + _slice.distance(from: start, to: end) } @inlinable @@ -395,7 +393,7 @@ extension Substring.UTF8View : BidirectionalCollection { _slice._failEarlyRangeCheck(range, bounds: bounds) } - public func index(before i: Index) -> Index { return _slice.index(before: i) } + public func index(before i: Index) -> Index { _slice.index(before: i) } public func formIndex(before i: inout Index) { _slice.formIndex(before: &i) @@ -412,12 +410,8 @@ extension Substring.UTF8View : BidirectionalCollection { extension Substring { @inlinable public var utf8: UTF8View { - get { - return base.utf8[startIndex.. Element { return _slice[index] } + public subscript(index: Index) -> Element { _slice[index] } @inlinable - public var indices: Indices { return _slice.indices } + public var indices: Indices { _slice.indices } @inlinable - public func index(after i: Index) -> Index { return _slice.index(after: i) } + public func index(after i: Index) -> Index { _slice.index(after: i) } @inlinable public func formIndex(after i: inout Index) { @@ -494,19 +488,19 @@ extension Substring.UTF16View : BidirectionalCollection { @inlinable public func index(_ i: Index, offsetBy n: Int) -> Index { - return _slice.index(i, offsetBy: n) + _slice.index(i, offsetBy: n) } @inlinable public func index( _ i: Index, offsetBy n: Int, limitedBy limit: Index ) -> Index? { - return _slice.index(i, offsetBy: n, limitedBy: limit) + _slice.index(i, offsetBy: n, limitedBy: limit) } @inlinable public func distance(from start: Index, to end: Index) -> Int { - return _slice.distance(from: start, to: end) + _slice.distance(from: start, to: end) } @inlinable @@ -522,7 +516,7 @@ extension Substring.UTF16View : BidirectionalCollection { } @inlinable - public func index(before i: Index) -> Index { return _slice.index(before: i) } + public func index(before i: Index) -> Index { _slice.index(before: i) } @inlinable public func formIndex(before i: inout Index) { @@ -531,19 +525,15 @@ extension Substring.UTF16View : BidirectionalCollection { @inlinable public subscript(r: Range) -> Substring.UTF16View { - return Substring.UTF16View(_slice.base, _bounds: r) + Substring.UTF16View(_slice.base, _bounds: r) } } extension Substring { @inlinable public var utf16: UTF16View { - get { - return base.utf16[startIndex.. Element { return _slice[index] } + public subscript(index: Index) -> Element { _slice[index] } @inlinable - public var indices: Indices { return _slice.indices } + public var indices: Indices { _slice.indices } @inlinable - public func index(after i: Index) -> Index { return _slice.index(after: i) } + public func index(after i: Index) -> Index { _slice.index(after: i) } @inlinable public func formIndex(after i: inout Index) { @@ -620,19 +610,19 @@ extension Substring.UnicodeScalarView : BidirectionalCollection { @inlinable public func index(_ i: Index, offsetBy n: Int) -> Index { - return _slice.index(i, offsetBy: n) + _slice.index(i, offsetBy: n) } @inlinable public func index( _ i: Index, offsetBy n: Int, limitedBy limit: Index ) -> Index? { - return _slice.index(i, offsetBy: n, limitedBy: limit) + _slice.index(i, offsetBy: n, limitedBy: limit) } @inlinable public func distance(from start: Index, to end: Index) -> Int { - return _slice.distance(from: start, to: end) + _slice.distance(from: start, to: end) } @inlinable @@ -648,7 +638,7 @@ extension Substring.UnicodeScalarView : BidirectionalCollection { } @inlinable - public func index(before i: Index) -> Index { return _slice.index(before: i) } + public func index(before i: Index) -> Index { _slice.index(before: i) } @inlinable public func formIndex(before i: inout Index) { @@ -657,19 +647,15 @@ extension Substring.UnicodeScalarView : BidirectionalCollection { @inlinable public subscript(r: Range) -> Substring.UnicodeScalarView { - return Substring.UnicodeScalarView(_slice.base, _bounds: r) + Substring.UnicodeScalarView(_slice.base, _bounds: r) } } extension Substring { @inlinable public var unicodeScalars: UnicodeScalarView { - get { - return base.unicodeScalars[startIndex.. String { - return String(self).lowercased() - } + public func lowercased() -> String { String(self).lowercased() } - public func uppercased() -> String { - return String(self).uppercased() - } + public func uppercased() -> String { String(self).uppercased() } public func filter( _ isIncluded: (Element) throws -> Bool ) rethrows -> String { - return try String(self.lazy.filter(isIncluded)) + try String(self.lazy.filter(isIncluded)) } } @@ -793,9 +775,7 @@ extension String { extension Substring { @inlinable @available(swift, introduced: 4) - public subscript(r: Range) -> Substring { - return Substring(_slice[r]) - } + public subscript(r: Range) -> Substring { Substring(_slice[r]) } } diff --git a/stdlib/public/core/UTF16.swift b/stdlib/public/core/UTF16.swift index c683284f2e6f7..7b688dfb6ffd0 100644 --- a/stdlib/public/core/UTF16.swift +++ b/stdlib/public/core/UTF16.swift @@ -42,7 +42,7 @@ extension Unicode.UTF16 { /// - Returns: The width of `x` when encoded in UTF-16, either `1` or `2`. @inlinable public static func width(_ x: Unicode.Scalar) -> Int { - return x.value <= UInt16.max ? 1 : 2 + x.value <= UInt16.max ? 1 : 2 } /// Returns the high-surrogate code unit of the surrogate pair representing @@ -116,7 +116,7 @@ extension Unicode.UTF16 { /// `false`. @inlinable public static func isLeadSurrogate(_ x: CodeUnit) -> Bool { - return (x & 0xFC00) == 0xD800 + (x & 0xFC00) == 0xD800 } /// Returns a Boolean value indicating whether the specified code unit is a @@ -143,14 +143,14 @@ extension Unicode.UTF16 { /// `false`. @inlinable public static func isTrailSurrogate(_ x: CodeUnit) -> Bool { - return (x & 0xFC00) == 0xDC00 + (x & 0xFC00) == 0xDC00 } /// Returns a Boolean value indicating whether the specified code unit is a /// high or low surrogate code unit. @_alwaysEmitIntoClient public static func isSurrogate(_ x: CodeUnit) -> Bool { - return isLeadSurrogate(x) || isTrailSurrogate(x) + isLeadSurrogate(x) || isTrailSurrogate(x) } @inlinable @@ -263,26 +263,20 @@ extension Unicode.UTF16 : Unicode.Encoding { public typealias CodeUnit = UInt16 public typealias EncodedScalar = _UIntBuffer - @inlinable - internal static var _replacementCodeUnit: CodeUnit { - @inline(__always) get { return 0xfffd } - } - + @inlinable @inline(__always) + internal static var _replacementCodeUnit: CodeUnit { 0xfffd } + @inlinable public static var encodedReplacementCharacter : EncodedScalar { - return EncodedScalar(_storage: 0xFFFD, _bitCount: 16) + EncodedScalar(_storage: 0xFFFD, _bitCount: 16) } /// Returns whether the given code unit represents an ASCII scalar @_alwaysEmitIntoClient - public static func isASCII(_ x: CodeUnit) -> Bool { - return x <= 0x7f - } + public static func isASCII(_ x: CodeUnit) -> Bool { x <= 0x7f } @inlinable - public static func _isScalar(_ x: CodeUnit) -> Bool { - return x & 0xf800 != 0xd800 - } + public static func _isScalar(_ x: CodeUnit) -> Bool { x & 0xf800 != 0xd800 } @inlinable @inline(__always) @@ -344,7 +338,7 @@ extension Unicode.UTF16 : Unicode.Encoding { s &>>= 8 r |= s & 0b0__11_1111 b = b &- 1 - + if _fastPath(b == 0) { return EncodedScalar(_storage: r & 0b0__111_1111_1111, _bitCount: 16) } @@ -352,11 +346,11 @@ extension Unicode.UTF16 : Unicode.Encoding { s &>>= 8 r |= s & 0b0__11_1111 b = b &- 1 - + if _fastPath(b == 0) { return EncodedScalar(_storage: r & 0xFFFF, _bitCount: 16) } - + r &<<= 6 s &>>= 8 r |= s & 0b0__11_1111 @@ -368,7 +362,7 @@ extension Unicode.UTF16 : Unicode.Encoding { } return encode(FromEncoding.decode(content)) } - + @_fixed_layout public struct ForwardParser { public typealias _Buffer = _UIntBuffer @@ -376,7 +370,7 @@ extension Unicode.UTF16 : Unicode.Encoding { public init() { _buffer = _Buffer() } public var _buffer: _Buffer } - + @_fixed_layout public struct ReverseParser { public typealias _Buffer = _UIntBuffer @@ -398,10 +392,10 @@ extension UTF16.ReverseParser : Unicode.Parser, _UTFParser { } return (false, 1*16) } - + @inlinable public func _bufferedScalar(bitCount: UInt8) -> Encoding.EncodedScalar { - return Encoding.EncodedScalar( + Encoding.EncodedScalar( _storage: (_buffer._storage &<< 16 | _buffer._storage &>> 16) &>> (32 - bitCount), _bitCount: bitCount @@ -411,7 +405,7 @@ extension UTF16.ReverseParser : Unicode.Parser, _UTFParser { extension Unicode.UTF16.ForwardParser : Unicode.Parser, _UTFParser { public typealias Encoding = Unicode.UTF16 - + @inlinable public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) { _internalInvariant( // this case handled elsewhere @@ -421,7 +415,7 @@ extension Unicode.UTF16.ForwardParser : Unicode.Parser, _UTFParser { } return (false, 1*16) } - + @inlinable public func _bufferedScalar(bitCount: UInt8) -> Encoding.EncodedScalar { var r = _buffer diff --git a/stdlib/public/core/UTF32.swift b/stdlib/public/core/UTF32.swift index 2f2d870ad1e9a..845586cdc343f 100644 --- a/stdlib/public/core/UTF32.swift +++ b/stdlib/public/core/UTF32.swift @@ -22,30 +22,26 @@ extension Unicode.UTF32 : Unicode.Encoding { @inlinable internal static var _replacementCodeUnit: CodeUnit { - @inline(__always) get { return 0xFFFD } + @inline(__always) get { 0xFFFD } } @inlinable public static var encodedReplacementCharacter : EncodedScalar { - return EncodedScalar(_replacementCodeUnit) + EncodedScalar(_replacementCodeUnit) } @inlinable @inline(__always) - public static func _isScalar(_ x: CodeUnit) -> Bool { - return true - } + public static func _isScalar(_ x: CodeUnit) -> Bool { true } /// Returns whether the given code unit represents an ASCII scalar @_alwaysEmitIntoClient - public static func isASCII(_ x: CodeUnit) -> Bool { - return x <= 0x7F - } + public static func isASCII(_ x: CodeUnit) -> Bool { x <= 0x7F } @inlinable @inline(__always) public static func decode(_ source: EncodedScalar) -> Unicode.Scalar { - return Unicode.Scalar(_unchecked: source.first!) + Unicode.Scalar(_unchecked: source.first!) } @inlinable @@ -53,15 +49,15 @@ extension Unicode.UTF32 : Unicode.Encoding { public static func encode( _ source: Unicode.Scalar ) -> EncodedScalar? { - return EncodedScalar(source.value) + EncodedScalar(source.value) } - + @_fixed_layout public struct Parser { @inlinable public init() { } } - + public typealias ForwardParser = Parser public typealias ReverseParser = Parser } @@ -80,7 +76,7 @@ extension UTF32.Parser : Unicode.Parser { // Check code unit is valid: not surrogate-reserved and within range. guard _fastPath((x &>> 11) != 0b1101_1 && x <= 0x10ffff) else { return .error(length: 1) } - + // x is a valid scalar. return .valid(UTF32.EncodedScalar(x)) } diff --git a/stdlib/public/core/UTF8.swift b/stdlib/public/core/UTF8.swift index 64f2d89bb84c6..669636ff47fab 100644 --- a/stdlib/public/core/UTF8.swift +++ b/stdlib/public/core/UTF8.swift @@ -56,21 +56,17 @@ extension Unicode.UTF8 : _UnicodeEncoding { @inlinable public static var encodedReplacementCharacter : EncodedScalar { - return EncodedScalar.encodedReplacementCharacter + EncodedScalar.encodedReplacementCharacter } @inline(__always) @inlinable - public static func _isScalar(_ x: CodeUnit) -> Bool { - return isASCII(x) - } + public static func _isScalar(_ x: CodeUnit) -> Bool { isASCII(x) } /// Returns whether the given code unit represents an ASCII scalar @_alwaysEmitIntoClient @inline(__always) - public static func isASCII(_ x: CodeUnit) -> Bool { - return x & 0b1000_0000 == 0 - } + public static func isASCII(_ x: CodeUnit) -> Bool { x & 0b1000_0000 == 0 } @inline(__always) @inlinable @@ -99,7 +95,7 @@ extension Unicode.UTF8 : _UnicodeEncoding { return Unicode.Scalar(_unchecked: value) } } - + @inline(__always) @inlinable public static func encode( @@ -136,7 +132,7 @@ extension Unicode.UTF8 : _UnicodeEncoding { ) -> EncodedScalar? { if _fastPath(FromEncoding.self == UTF16.self) { let c = _identityCast(content, to: UTF16.EncodedScalar.self) - var u0 = UInt16(truncatingIfNeeded: c._storage) + var u0 = UInt16(truncatingIfNeeded: c._storage) if _fastPath(u0 < 0x80) { return EncodedScalar(_containing: UInt8(truncatingIfNeeded: u0)) } @@ -169,7 +165,7 @@ extension Unicode.UTF8 : _UnicodeEncoding { public init() { _buffer = _Buffer() } public var _buffer: _Buffer } - + @_fixed_layout public struct ReverseParser { public typealias _Buffer = _UIntBuffer @@ -246,7 +242,7 @@ extension UTF8.ReverseParser : Unicode.Parser, _UTFParser { } return 1 } - + @inline(__always) @inlinable public func _bufferedScalar(bitCount: UInt8) -> Encoding.EncodedScalar { @@ -263,7 +259,7 @@ extension Unicode.UTF8.ForwardParser : Unicode.Parser, _UTFParser { @inlinable public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) { _internalInvariant(_buffer._storage & 0x80 != 0) // this case handled elsewhere - + if _buffer._storage & 0b0__1100_0000__1110_0000 == 0b0__1000_0000__1100_0000 { // 2-byte sequence. At least one of the top 4 bits of the decoded result @@ -317,7 +313,7 @@ extension Unicode.UTF8.ForwardParser : Unicode.Parser, _UTFParser { } return 1 } - + @inlinable public func _bufferedScalar(bitCount: UInt8) -> Encoding.EncodedScalar { let x = UInt32(_buffer._storage) &+ 0x01010101 diff --git a/stdlib/public/core/Unicode.swift b/stdlib/public/core/Unicode.swift index fd2123797bc08..3e09d07939d4b 100644 --- a/stdlib/public/core/Unicode.swift +++ b/stdlib/public/core/Unicode.swift @@ -24,10 +24,10 @@ import SwiftShims public enum UnicodeDecodingResult : Equatable { /// A decoded Unicode scalar value. case scalarValue(Unicode.Scalar) - + /// An indication that no more Unicode scalars are available in the input. case emptyInput - + /// An indication of a decoding error. case error @@ -296,21 +296,21 @@ extension Unicode.UTF8 : UnicodeCodec { /// - Returns: `true` if `byte` is a continuation byte; otherwise, `false`. @inlinable public static func isContinuation(_ byte: CodeUnit) -> Bool { - return byte & 0b11_00__0000 == 0b10_00__0000 + byte & 0b11_00__0000 == 0b10_00__0000 } @inlinable public static func _nullCodeUnitOffset( in input: UnsafePointer ) -> Int { - return Int(_swift_stdlib_strlen_unsigned(input)) + Int(_swift_stdlib_strlen_unsigned(input)) } // Support parsing C strings as-if they are UTF8 strings. @inlinable public static func _nullCodeUnitOffset( in input: UnsafePointer ) -> Int { - return Int(_swift_stdlib_strlen(input)) + Int(_swift_stdlib_strlen(input)) } } @@ -479,7 +479,7 @@ extension Unicode.UTF32 : UnicodeCodec { _ input: inout I ) -> UnicodeDecodingResult where I.Element == CodeUnit { var parser = ForwardParser() - + switch parser.parseScalar(from: &input) { case .valid(let s): return .scalarValue(UTF32.decode(s)) case .error: return .error @@ -600,14 +600,14 @@ extension UTF16.CodeUnit : _StringElement { @inlinable public // @testable static func _toUTF16CodeUnit(_ x: UTF16.CodeUnit) -> UTF16.CodeUnit { - return x + x } @inlinable public // @testable static func _fromUTF16CodeUnit( _ utf16: UTF16.CodeUnit ) -> UTF16.CodeUnit { - return utf16 + utf16 } } diff --git a/stdlib/public/core/UnicodeEncoding.swift b/stdlib/public/core/UnicodeEncoding.swift index 82e9089b9d4b1..c3fb5aa18f98a 100644 --- a/stdlib/public/core/UnicodeEncoding.swift +++ b/stdlib/public/core/UnicodeEncoding.swift @@ -13,7 +13,7 @@ public protocol _UnicodeEncoding { /// The basic unit of encoding associatedtype CodeUnit : UnsignedInteger, FixedWidthInteger - + /// A valid scalar value as represented in this encoding associatedtype EncodedScalar : BidirectionalCollection where EncodedScalar.Iterator.Element == CodeUnit @@ -35,7 +35,7 @@ public protocol _UnicodeEncoding { /// Converts a scalar from another encoding's representation, returning /// `nil` if the scalar can't be represented in this encoding. /// - /// A default implementation of this method will be provided + /// A default implementation of this method will be provided /// automatically for any conforming type that does not implement one. static func transcode( _ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type @@ -45,7 +45,7 @@ public protocol _UnicodeEncoding { /// `EncodedScalar`s. associatedtype ForwardParser : Unicode.Parser where ForwardParser.Encoding == Self - + /// A type that can be used to parse a reversed sequence of /// `CodeUnits` into `EncodedScalar`s. associatedtype ReverseParser : Unicode.Parser @@ -63,13 +63,13 @@ public protocol _UnicodeEncoding { extension _UnicodeEncoding { // See note on declaration of requirement, above @inlinable - public static func _isScalar(_ x: CodeUnit) -> Bool { return false } + public static func _isScalar(_ x: CodeUnit) -> Bool { false } @inlinable public static func transcode( _ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type ) -> EncodedScalar? { - return encode(FromEncoding.decode(content)) + encode(FromEncoding.decode(content)) } /// Converts from encoding-independent to encoded representation, returning @@ -77,7 +77,7 @@ extension _UnicodeEncoding { /// encoding. @inlinable internal static func _encode(_ content: Unicode.Scalar) -> EncodedScalar { - return encode(content) ?? encodedReplacementCharacter + encode(content) ?? encodedReplacementCharacter } /// Converts a scalar from another encoding's representation, returning @@ -87,7 +87,7 @@ extension _UnicodeEncoding { internal static func _transcode( _ content: FromEncoding.EncodedScalar, from _: FromEncoding.Type ) -> EncodedScalar { - return transcode(content, from: FromEncoding.self) + transcode(content, from: FromEncoding.self) ?? encodedReplacementCharacter } diff --git a/stdlib/public/core/UnicodeHelpers.swift b/stdlib/public/core/UnicodeHelpers.swift index d0addb39ddb23..b5418f0bacf47 100644 --- a/stdlib/public/core/UnicodeHelpers.swift +++ b/stdlib/public/core/UnicodeHelpers.swift @@ -136,9 +136,7 @@ internal func _utf8ScalarLength( @inlinable @inline(__always) -internal func _continuationPayload(_ x: UInt8) -> UInt32 { - return UInt32(x & 0x3F) -} +internal func _continuationPayload(_ x: UInt8) -> UInt32 { UInt32(x & 0x3F) } @inlinable @inline(__always) internal func _scalarAlign( diff --git a/stdlib/public/core/UnicodeScalar.swift b/stdlib/public/core/UnicodeScalar.swift index 882757688d3b7..80879202fee63 100644 --- a/stdlib/public/core/UnicodeScalar.swift +++ b/stdlib/public/core/UnicodeScalar.swift @@ -49,7 +49,7 @@ extension Unicode.Scalar : ExpressibleByUnicodeScalarLiteral { /// A numeric representation of the Unicode scalar. @inlinable - public var value: UInt32 { return _value } + public var value: UInt32 { _value } @_transparent public init(_builtinUnicodeScalarLiteral value: Builtin.Int32) { @@ -264,28 +264,22 @@ extension Unicode.Scalar : /// // Prints "รณ false 243" /// // Prints "n true 110" @inlinable - public var isASCII: Bool { - return value <= 127 - } + public var isASCII: Bool { value <= 127 } // FIXME: Unicode makes this interesting. internal var _isPrintableASCII: Bool { - return (self >= Unicode.Scalar(0o040) && self <= Unicode.Scalar(0o176)) + (self >= Unicode.Scalar(0o040) && self <= Unicode.Scalar(0o176)) } } extension Unicode.Scalar : CustomStringConvertible, CustomDebugStringConvertible { /// A textual representation of the Unicode scalar. @inlinable - public var description: String { - return String(self) - } + public var description: String { String(self) } /// An escaped textual representation of the Unicode scalar, suitable for /// debugging. - public var debugDescription: String { - return "\"\(escaped(asASCII: true))\"" - } + public var debugDescription: String { "\"\(escaped(asASCII: true))\"" } } extension Unicode.Scalar : LosslessStringConvertible { @@ -374,14 +368,14 @@ extension UInt64 { extension Unicode.Scalar : Equatable { @inlinable public static func == (lhs: Unicode.Scalar, rhs: Unicode.Scalar) -> Bool { - return lhs.value == rhs.value + lhs.value == rhs.value } } extension Unicode.Scalar : Comparable { @inlinable public static func < (lhs: Unicode.Scalar, rhs: Unicode.Scalar) -> Bool { - return lhs.value < rhs.value + lhs.value < rhs.value } } @@ -397,9 +391,7 @@ extension Unicode.Scalar { } @inlinable - public var utf16: UTF16View { - return UTF16View(value: self) - } + public var utf16: UTF16View { UTF16View(value: self) } } extension Unicode.Scalar.UTF16View : RandomAccessCollection { @@ -408,18 +400,14 @@ extension Unicode.Scalar.UTF16View : RandomAccessCollection { /// The position of the first code unit. @inlinable - public var startIndex: Int { - return 0 - } + public var startIndex: Int { 0 } /// The "past the end" position---that is, the position one /// greater than the last valid subscript argument. /// /// If the collection is empty, `endIndex` is equal to `startIndex`. @inlinable - public var endIndex: Int { - return 0 + UTF16.width(value) - } + public var endIndex: Int { 0 + UTF16.width(value) } /// Accesses the code unit at the specified position. /// @@ -428,7 +416,7 @@ extension Unicode.Scalar.UTF16View : RandomAccessCollection { /// `endIndex` property. @inlinable public subscript(position: Int) -> UTF16.CodeUnit { - return position == 0 ? ( + position == 0 ? ( endIndex == 1 ? UTF16.CodeUnit(value.value) : UTF16.leadSurrogate(value) ) : UTF16.trailSurrogate(value) } @@ -448,7 +436,7 @@ extension Unicode.Scalar { @available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) @inlinable - public var utf8: UTF8View { return UTF8View(value: self) } + public var utf8: UTF8View { UTF8View(value: self) } } @available(macOS 9999, iOS 9999, tvOS 9999, watchOS 9999, *) @@ -457,14 +445,14 @@ extension Unicode.Scalar.UTF8View : RandomAccessCollection { /// The position of the first code unit. @inlinable - public var startIndex: Int { return 0 } + public var startIndex: Int { 0 } /// The "past the end" position---that is, the position one /// greater than the last valid subscript argument. /// /// If the collection is empty, `endIndex` is equal to `startIndex`. @inlinable - public var endIndex: Int { return 0 + UTF8.width(value) } + public var endIndex: Int { 0 + UTF8.width(value) } /// Accesses the code unit at the specified position. /// @@ -481,7 +469,7 @@ extension Unicode.Scalar.UTF8View : RandomAccessCollection { extension Unicode.Scalar { internal static var _replacementCharacter: Unicode.Scalar { - return Unicode.Scalar(_value: UTF32._replacementCodeUnit) + Unicode.Scalar(_value: UTF32._replacementCodeUnit) } } diff --git a/stdlib/public/core/UnicodeScalarProperties.swift b/stdlib/public/core/UnicodeScalarProperties.swift index 21a6796162936..05c13fd48238f 100644 --- a/stdlib/public/core/UnicodeScalarProperties.swift +++ b/stdlib/public/core/UnicodeScalarProperties.swift @@ -29,7 +29,7 @@ extension Unicode.Scalar { // Provide the value as UChar32 to make calling the ICU APIs cleaner internal var icuValue: __swift_stdlib_UChar32 { - return __swift_stdlib_UChar32(bitPattern: self._scalar._value) + __swift_stdlib_UChar32(bitPattern: self._scalar._value) } } @@ -44,9 +44,7 @@ extension Unicode.Scalar { /// $0.properties.isMath /// }) /// // hasMathSymbols == true - public var properties: Properties { - return Properties(self) - } + public var properties: Properties { Properties(self) } } /// Boolean properties that are defined by the Unicode Standard (i.e., not @@ -55,7 +53,7 @@ extension Unicode.Scalar.Properties { internal func _hasBinaryProperty( _ property: __swift_stdlib_UProperty ) -> Bool { - return __swift_stdlib_u_hasBinaryProperty(icuValue, property) != 0 + __swift_stdlib_u_hasBinaryProperty(icuValue, property) != 0 } /// A Boolean value indicating whether the scalar is alphabetic. @@ -65,7 +63,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Alphabetic" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isAlphabetic: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_ALPHABETIC) + _hasBinaryProperty(__swift_stdlib_UCHAR_ALPHABETIC) } /// A Boolean value indicating whether the scalar is an ASCII character @@ -80,7 +78,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "ASCII_Hex_Digit" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isASCIIHexDigit: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_ASCII_HEX_DIGIT) + _hasBinaryProperty(__swift_stdlib_UCHAR_ASCII_HEX_DIGIT) } /// A Boolean value indicating whether the scalar is a format control @@ -90,7 +88,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Bidi_Control" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isBidiControl: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_BIDI_CONTROL) + _hasBinaryProperty(__swift_stdlib_UCHAR_BIDI_CONTROL) } /// A Boolean value indicating whether the scalar is mirrored in @@ -99,7 +97,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Bidi_Mirrored" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isBidiMirrored: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_BIDI_MIRRORED) + _hasBinaryProperty(__swift_stdlib_UCHAR_BIDI_MIRRORED) } /// A Boolean value indicating whether the scalar is a punctuation @@ -108,9 +106,7 @@ extension Unicode.Scalar.Properties { /// /// This property corresponds to the "Dash" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). - public var isDash: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_DASH) - } + public var isDash: Bool { _hasBinaryProperty(__swift_stdlib_UCHAR_DASH) } /// A Boolean value indicating whether the scalar is a default-ignorable /// code point. @@ -123,7 +119,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Default_Ignorable_Code_Point" property /// in the [Unicode Standard](http://www.unicode.org/versions/latest/). public var isDefaultIgnorableCodePoint: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_DEFAULT_IGNORABLE_CODE_POINT) + _hasBinaryProperty(__swift_stdlib_UCHAR_DEFAULT_IGNORABLE_CODE_POINT) } /// A Boolean value indicating whether the scalar is deprecated. @@ -134,7 +130,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Deprecated" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isDeprecated: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_DEPRECATED) + _hasBinaryProperty(__swift_stdlib_UCHAR_DEPRECATED) } /// A Boolean value indicating whether the scalar is a diacritic. @@ -146,7 +142,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Diacritic" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isDiacritic: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_DIACRITIC) + _hasBinaryProperty(__swift_stdlib_UCHAR_DIACRITIC) } /// A Boolean value indicating whether the scalar's principal function is @@ -157,7 +153,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Extender" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isExtender: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_EXTENDER) + _hasBinaryProperty(__swift_stdlib_UCHAR_EXTENDER) } /// A Boolean value indicating whether the scalar is excluded from @@ -166,7 +162,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Full_Composition_Exclusion" property in /// the [Unicode Standard](http://www.unicode.org/versions/latest/). public var isFullCompositionExclusion: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_FULL_COMPOSITION_EXCLUSION) + _hasBinaryProperty(__swift_stdlib_UCHAR_FULL_COMPOSITION_EXCLUSION) } /// A Boolean value indicating whether the scalar is a grapheme base. @@ -183,7 +179,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Grapheme_Base" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isGraphemeBase: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_GRAPHEME_BASE) + _hasBinaryProperty(__swift_stdlib_UCHAR_GRAPHEME_BASE) } /// A Boolean value indicating whether the scalar is a grapheme extender. @@ -200,7 +196,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Grapheme_Extend" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isGraphemeExtend: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_GRAPHEME_EXTEND) + _hasBinaryProperty(__swift_stdlib_UCHAR_GRAPHEME_EXTEND) } /// A Boolean value indicating whether the scalar is one that is commonly @@ -213,7 +209,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Hex_Digit" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isHexDigit: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_HEX_DIGIT) + _hasBinaryProperty(__swift_stdlib_UCHAR_HEX_DIGIT) } /// A Boolean value indicating whether the scalar is one which is @@ -227,7 +223,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "ID_Continue" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isIDContinue: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_ID_CONTINUE) + _hasBinaryProperty(__swift_stdlib_UCHAR_ID_CONTINUE) } /// A Boolean value indicating whether the scalar is one which is @@ -241,7 +237,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "ID_Start" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isIDStart: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_ID_START) + _hasBinaryProperty(__swift_stdlib_UCHAR_ID_START) } /// A Boolean value indicating whether the scalar is considered to be a @@ -255,7 +251,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Ideographic" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isIdeographic: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_IDEOGRAPHIC) + _hasBinaryProperty(__swift_stdlib_UCHAR_IDEOGRAPHIC) } /// A Boolean value indicating whether the scalar is an ideographic @@ -270,7 +266,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "IDS_Binary_Operator" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isIDSBinaryOperator: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_IDS_BINARY_OPERATOR) + _hasBinaryProperty(__swift_stdlib_UCHAR_IDS_BINARY_OPERATOR) } /// A Boolean value indicating whether the scalar is an ideographic @@ -285,7 +281,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "IDS_Trinary_Operator" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isIDSTrinaryOperator: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_IDS_TRINARY_OPERATOR) + _hasBinaryProperty(__swift_stdlib_UCHAR_IDS_TRINARY_OPERATOR) } /// A Boolean value indicating whether the scalar is a format control @@ -311,7 +307,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Join_Control" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isJoinControl: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_JOIN_CONTROL) + _hasBinaryProperty(__swift_stdlib_UCHAR_JOIN_CONTROL) } /// A Boolean value indicating whether the scalar requires special handling @@ -325,7 +321,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Logical_Order_Exception" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isLogicalOrderException: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_LOGICAL_ORDER_EXCEPTION) + _hasBinaryProperty(__swift_stdlib_UCHAR_LOGICAL_ORDER_EXCEPTION) } /// A Boolean value indicating whether the scalar's letterform is @@ -334,7 +330,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Lowercase" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isLowercase: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_LOWERCASE) + _hasBinaryProperty(__swift_stdlib_UCHAR_LOWERCASE) } /// A Boolean value indicating whether the scalar is one that naturally @@ -349,9 +345,7 @@ extension Unicode.Scalar.Properties { /// /// This property corresponds to the "Math" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). - public var isMath: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_MATH) - } + public var isMath: Bool { _hasBinaryProperty(__swift_stdlib_UCHAR_MATH) } /// A Boolean value indicating whether the scalar is permanently reserved /// for internal use. @@ -359,7 +353,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Noncharacter_Code_Point" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isNoncharacterCodePoint: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_NONCHARACTER_CODE_POINT) + _hasBinaryProperty(__swift_stdlib_UCHAR_NONCHARACTER_CODE_POINT) } /// A Boolean value indicating whether the scalar is one that is used in @@ -368,7 +362,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Quotation_Mark" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isQuotationMark: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_QUOTATION_MARK) + _hasBinaryProperty(__swift_stdlib_UCHAR_QUOTATION_MARK) } /// A Boolean value indicating whether the scalar is a radical component of @@ -381,7 +375,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Radical" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isRadical: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_RADICAL) + _hasBinaryProperty(__swift_stdlib_UCHAR_RADICAL) } /// A Boolean value indicating whether the scalar has a "soft dot" that @@ -393,7 +387,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Soft_Dotted" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isSoftDotted: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_SOFT_DOTTED) + _hasBinaryProperty(__swift_stdlib_UCHAR_SOFT_DOTTED) } /// A Boolean value indicating whether the scalar is a punctuation symbol @@ -402,7 +396,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Terminal_Punctuation" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isTerminalPunctuation: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_TERMINAL_PUNCTUATION) + _hasBinaryProperty(__swift_stdlib_UCHAR_TERMINAL_PUNCTUATION) } /// A Boolean value indicating whether the scalar is one of the unified @@ -415,7 +409,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Unified_Ideograph" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isUnifiedIdeograph: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_UNIFIED_IDEOGRAPH) + _hasBinaryProperty(__swift_stdlib_UCHAR_UNIFIED_IDEOGRAPH) } /// A Boolean value indicating whether the scalar's letterform is @@ -424,7 +418,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Uppercase" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isUppercase: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_UPPERCASE) + _hasBinaryProperty(__swift_stdlib_UCHAR_UPPERCASE) } /// A Boolean value indicating whether the scalar is a whitespace @@ -437,7 +431,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "White_Space" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isWhitespace: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_WHITE_SPACE) + _hasBinaryProperty(__swift_stdlib_UCHAR_WHITE_SPACE) } /// A Boolean value indicating whether the scalar is one which is @@ -452,7 +446,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "XID_Continue" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isXIDContinue: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_XID_CONTINUE) + _hasBinaryProperty(__swift_stdlib_UCHAR_XID_CONTINUE) } /// A Boolean value indicating whether the scalar is one which is @@ -467,7 +461,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "XID_Start" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isXIDStart: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_XID_START) + _hasBinaryProperty(__swift_stdlib_UCHAR_XID_START) } /// A Boolean value indicating whether the scalar is a punctuation mark @@ -476,7 +470,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Sentence_Terminal" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isSentenceTerminal: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_S_TERM) + _hasBinaryProperty(__swift_stdlib_UCHAR_S_TERM) } /// A Boolean value indicating whether the scalar is a variation selector. @@ -487,7 +481,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Variation_Selector" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isVariationSelector: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_VARIATION_SELECTOR) + _hasBinaryProperty(__swift_stdlib_UCHAR_VARIATION_SELECTOR) } /// A Boolean value indicating whether the scalar is recommended to have @@ -496,7 +490,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Pattern_Syntax" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isPatternSyntax: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_PATTERN_SYNTAX) + _hasBinaryProperty(__swift_stdlib_UCHAR_PATTERN_SYNTAX) } /// A Boolean value indicating whether the scalar is recommended to be @@ -505,7 +499,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Pattern_White_Space" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isPatternWhitespace: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_PATTERN_WHITE_SPACE) + _hasBinaryProperty(__swift_stdlib_UCHAR_PATTERN_WHITE_SPACE) } /// A Boolean value indicating whether the scalar is considered to be @@ -520,9 +514,7 @@ extension Unicode.Scalar.Properties { /// /// This property corresponds to the "Cased" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). - public var isCased: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_CASED) - } + public var isCased: Bool { _hasBinaryProperty(__swift_stdlib_UCHAR_CASED) } /// A Boolean value indicating whether the scalar is ignored for casing /// purposes. @@ -530,7 +522,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Case_Ignorable" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var isCaseIgnorable: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_CASE_IGNORABLE) + _hasBinaryProperty(__swift_stdlib_UCHAR_CASE_IGNORABLE) } /// A Boolean value indicating whether the scalar's normalized form differs @@ -539,7 +531,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Changes_When_Lowercased" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var changesWhenLowercased: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_LOWERCASED) + _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_LOWERCASED) } /// A Boolean value indicating whether the scalar's normalized form differs @@ -548,7 +540,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Changes_When_Uppercased" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var changesWhenUppercased: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_UPPERCASED) + _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_UPPERCASED) } /// A Boolean value indicating whether the scalar's normalized form differs @@ -557,7 +549,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Changes_When_Titlecased" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var changesWhenTitlecased: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_TITLECASED) + _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_TITLECASED) } /// A Boolean value indicating whether the scalar's normalized form differs @@ -566,7 +558,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Changes_When_Casefolded" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var changesWhenCaseFolded: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_CASEFOLDED) + _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_CASEFOLDED) } /// A Boolean value indicating whether the scalar may change when it @@ -578,7 +570,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Changes_When_Casemapped" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var changesWhenCaseMapped: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_CASEMAPPED) + _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_CASEMAPPED) } /// A Boolean value indicating whether the scalar is one that is not @@ -587,7 +579,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Changes_When_NFKC_Casefolded" property /// in the [Unicode Standard](http://www.unicode.org/versions/latest/). public var changesWhenNFKCCaseFolded: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_NFKC_CASEFOLDED) + _hasBinaryProperty(__swift_stdlib_UCHAR_CHANGES_WHEN_NFKC_CASEFOLDED) } #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) @@ -626,9 +618,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Emoji" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). @available(macOS 10.12.2, iOS 10.2, tvOS 10.1, watchOS 3.1.1, *) - public var isEmoji: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_EMOJI) - } + public var isEmoji: Bool { _hasBinaryProperty(__swift_stdlib_UCHAR_EMOJI) } /// A Boolean value indicating whether the scalar is one that should be /// rendered with an emoji presentation, rather than a text presentation, by @@ -644,7 +634,7 @@ extension Unicode.Scalar.Properties { /// [Unicode Standard](http://www.unicode.org/versions/latest/). @available(macOS 10.12.2, iOS 10.2, tvOS 10.1, watchOS 3.1.1, *) public var isEmojiPresentation: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_EMOJI_PRESENTATION) + _hasBinaryProperty(__swift_stdlib_UCHAR_EMOJI_PRESENTATION) } /// A Boolean value indicating whether the scalar is one that can modify @@ -658,7 +648,7 @@ extension Unicode.Scalar.Properties { /// [Unicode Standard](http://www.unicode.org/versions/latest/). @available(macOS 10.12.2, iOS 10.2, tvOS 10.1, watchOS 3.1.1, *) public var isEmojiModifier: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_EMOJI_MODIFIER) + _hasBinaryProperty(__swift_stdlib_UCHAR_EMOJI_MODIFIER) } /// A Boolean value indicating whether the scalar is one whose appearance @@ -668,7 +658,7 @@ extension Unicode.Scalar.Properties { /// [Unicode Standard](http://www.unicode.org/versions/latest/). @available(macOS 10.12.2, iOS 10.2, tvOS 10.1, watchOS 3.1.1, *) public var isEmojiModifierBase: Bool { - return _hasBinaryProperty(__swift_stdlib_UCHAR_EMOJI_MODIFIER_BASE) + _hasBinaryProperty(__swift_stdlib_UCHAR_EMOJI_MODIFIER_BASE) } #endif } @@ -729,7 +719,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Lowercase_Mapping" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var lowercaseMapping: String { - return _applyMapping(__swift_stdlib_u_strToLower) + _applyMapping(__swift_stdlib_u_strToLower) } /// The titlecase mapping of the scalar. @@ -743,7 +733,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Titlecase_Mapping" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var titlecaseMapping: String { - return _applyMapping { ptr, cap, src, len, locale, err in + _applyMapping { ptr, cap, src, len, locale, err in return __swift_stdlib_u_strToTitle(ptr, cap, src, len, nil, locale, err) } } @@ -759,7 +749,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Uppercase_Mapping" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var uppercaseMapping: String { - return _applyMapping(__swift_stdlib_u_strToUpper) + _applyMapping(__swift_stdlib_u_strToUpper) } } @@ -1123,9 +1113,7 @@ extension Unicode.Scalar.Properties { /// /// This property corresponds to the "Name" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). - public var name: String? { - return _scalarName(__swift_stdlib_U_UNICODE_CHAR_NAME) - } + public var name: String? { _scalarName(__swift_stdlib_U_UNICODE_CHAR_NAME) } /// The normative formal alias of the scalar. /// @@ -1141,7 +1129,7 @@ extension Unicode.Scalar.Properties { /// This property corresponds to the "Name_Alias" property in the /// [Unicode Standard](http://www.unicode.org/versions/latest/). public var nameAlias: String? { - return _scalarName(__swift_stdlib_U_CHAR_NAME_ALIAS) + _scalarName(__swift_stdlib_U_CHAR_NAME_ALIAS) } } @@ -1264,18 +1252,18 @@ extension Unicode { lhs: CanonicalCombiningClass, rhs: CanonicalCombiningClass ) -> Bool { - return lhs.rawValue == rhs.rawValue + lhs.rawValue == rhs.rawValue } public static func < ( lhs: CanonicalCombiningClass, rhs: CanonicalCombiningClass ) -> Bool { - return lhs.rawValue < rhs.rawValue + lhs.rawValue < rhs.rawValue } public var hashValue: Int { - return rawValue.hashValue + rawValue.hashValue } public func hash(into hasher: inout Hasher) { diff --git a/stdlib/public/core/ValidUTF8Buffer.swift b/stdlib/public/core/ValidUTF8Buffer.swift index 2aa4e47750541..ef0bb6ba48675 100644 --- a/stdlib/public/core/ValidUTF8Buffer.swift +++ b/stdlib/public/core/ValidUTF8Buffer.swift @@ -55,9 +55,7 @@ extension _ValidUTF8Buffer : Sequence { } @inlinable - public func makeIterator() -> Iterator { - return Iterator(self) - } + public func makeIterator() -> Iterator { Iterator(self) } } extension _ValidUTF8Buffer : Collection { @@ -71,33 +69,27 @@ extension _ValidUTF8Buffer : Collection { @inlinable public static func == (lhs: Index, rhs: Index) -> Bool { - return lhs._biasedBits == rhs._biasedBits + lhs._biasedBits == rhs._biasedBits } @inlinable public static func < (lhs: Index, rhs: Index) -> Bool { - return lhs._biasedBits > rhs._biasedBits + lhs._biasedBits > rhs._biasedBits } } @inlinable - public var startIndex : Index { - return Index(_biasedBits: _biasedBits) - } + public var startIndex : Index { Index(_biasedBits: _biasedBits) } @inlinable - public var endIndex : Index { - return Index(_biasedBits: 0) - } + public var endIndex : Index { Index(_biasedBits: 0) } @inlinable public var count : Int { - return UInt32.bitWidth &>> 3 &- _biasedBits.leadingZeroBitCount &>> 3 + UInt32.bitWidth &>> 3 &- _biasedBits.leadingZeroBitCount &>> 3 } @inlinable - public var isEmpty : Bool { - return _biasedBits == 0 - } + public var isEmpty : Bool { _biasedBits == 0 } @inlinable public func index(after i: Index) -> Index { @@ -107,7 +99,7 @@ extension _ValidUTF8Buffer : Collection { @inlinable public subscript(i: Index) -> Element { - return Element(truncatingIfNeeded: i._biasedBits) &- 1 + Element(truncatingIfNeeded: i._biasedBits) &- 1 } } @@ -151,14 +143,10 @@ extension _ValidUTF8Buffer : RangeReplaceableCollection { } @inlinable - public var capacity: Int { - return _ValidUTF8Buffer.capacity - } + public var capacity: Int { _ValidUTF8Buffer.capacity } @inlinable - public static var capacity: Int { - return UInt32.bitWidth / Element.bitWidth - } + public static var capacity: Int { UInt32.bitWidth / Element.bitWidth } @inlinable @inline(__always) @@ -181,7 +169,7 @@ extension _ValidUTF8Buffer : RangeReplaceableCollection { @inlinable internal func _isValid(_ i: Index) -> Bool { - return i == endIndex || indices.contains(i) + i == endIndex || indices.contains(i) } @inlinable @@ -212,7 +200,7 @@ extension _ValidUTF8Buffer { extension _ValidUTF8Buffer { @inlinable public static var encodedReplacementCharacter : _ValidUTF8Buffer { - return _ValidUTF8Buffer(_biasedBits: 0xBD_BF_EF &+ 0x01_01_01) + _ValidUTF8Buffer(_biasedBits: 0xBD_BF_EF &+ 0x01_01_01) } @inlinable diff --git a/validation-test/stdlib/String.swift b/validation-test/stdlib/String.swift index 02577109ccfbc..a04c764cb57a6 100644 --- a/validation-test/stdlib/String.swift +++ b/validation-test/stdlib/String.swift @@ -40,27 +40,24 @@ extension String { return self._classify()._capacity } var capacity: Int { - return self._classify()._capacity + self._classify()._capacity } var unusedCapacity: Int { - return Swift.max(0, self._classify()._capacity - self._classify()._count) - } - var bufferID: ObjectIdentifier? { - return _rawIdentifier() + Swift.max(0, self._classify()._capacity - self._classify()._count) } + var bufferID: ObjectIdentifier? { _rawIdentifier() } + func _rawIdentifier() -> ObjectIdentifier? { - return self._classify()._objectIdentifier + self._classify()._objectIdentifier } var byteWidth: Int { - return _classify()._isASCII ? 1 : 2 + _classify()._isASCII ? 1 : 2 } } extension Substring { - var bufferID: ObjectIdentifier? { - return base.bufferID - } + var bufferID: ObjectIdentifier? { base.bufferID } } // A thin wrapper around _StringGuts implementing RangeReplaceableCollection @@ -78,14 +75,14 @@ struct StringFauxUTF16Collection: RangeReplaceableCollection, RandomAccessCollec } var _str: String - var _guts: _StringGuts { return _str._guts } + var _guts: _StringGuts { _str._guts } - var startIndex: Index { return 0 } - var endIndex: Index { return _str.utf16.count } - var indices: Indices { return startIndex.. Element { - return _str.utf16[_str._toUTF16Index(position)] + _str.utf16[_str._toUTF16Index(position)] } mutating func replaceSubrange(