Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions stdlib/public/core/ASCII.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -73,7 +71,7 @@ extension Unicode.ASCII : Unicode.Encoding {
@inlinable
public init() { }
}

public typealias ForwardParser = Parser
public typealias ReverseParser = Parser
}
Expand Down
12 changes: 4 additions & 8 deletions stdlib/public/core/CString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,15 @@ extension String {
}

extension UnsafePointer where Pointee == UInt8 {
@inlinable
@inlinable @inline(__always)
internal var _asCChar: UnsafePointer<CChar> {
@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<UInt8> {
@inline(__always) get {
return UnsafeRawPointer(self).assumingMemoryBound(to: UInt8.self)
}
UnsafeRawPointer(self).assumingMemoryBound(to: UInt8.self)
}
}

22 changes: 11 additions & 11 deletions stdlib/public/core/SmallString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -185,7 +185,7 @@ extension _SmallString: RandomAccessCollection, MutableCollection {
@inlinable @inline(__always)
internal subscript(_ bounds: Range<Index>) -> 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
}
Expand Down
18 changes: 5 additions & 13 deletions stdlib/public/core/StaticString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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) }
}
20 changes: 10 additions & 10 deletions stdlib/public/core/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ extension Sequence where Element: StringProtocol {
@_specialize(where Self == Array<Substring>)
@_specialize(where Self == Array<String>)
public func joined(separator: String = "") -> String {
return _joined(separator: separator)
_joined(separator: separator)
}

@inline(__always) // Pick up @_specialize and devirtualize from two callers
Expand Down Expand Up @@ -645,7 +645,7 @@ extension BidirectionalCollection where Element == String {
/// - Returns: A single, concatenated string.
@_specialize(where Self == Array<String>)
public func joined(separator: String = "") -> String {
return _joined(separator: separator)
_joined(separator: separator)
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -889,20 +889,20 @@ 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()
icuInputBuffer.deallocate()
icuOutputBuffer.deallocate()
}
}

while index < cachedEndIndex {
let result = _foreignNormalize(
readIndex: index,
Expand Down Expand Up @@ -938,17 +938,17 @@ internal func _fastWithNormalizedCodeUnitsImpl(

var index = String.Index(_encodedOffset: 0)
let cachedEndIndex = String.Index(_encodedOffset: sourceBuffer.count)

var hasBufferOwnership = false

defer {
if hasBufferOwnership {
outputBuffer.deallocate()
icuInputBuffer.deallocate()
icuOutputBuffer.deallocate()
}
}

while index < cachedEndIndex {
let result = _fastNormalize(
readIndex: index,
Expand Down
7 changes: 3 additions & 4 deletions stdlib/public/core/StringBreadcrumbs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading