Skip to content

Commit d8f1caf

Browse files
author
Dave Abrahams
committed
Inline all the new low-level bits
1 parent c339102 commit d8f1caf

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

stdlib/public/core/UTF8.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
extension _Unicode {
13+
@_fixed_layout
1314
public enum UTF8 {
1415
case _swift3Buffer(_Unicode.UTF8.ForwardParser)
1516
}
@@ -23,10 +24,14 @@ extension _Unicode.UTF8 : UnicodeEncoding {
2324
return EncodedScalar(_storage: 0xbdbfef, _bitCount: 24)
2425
}
2526

27+
@inline(__always)
28+
@_inlineable
2629
public static func _isScalar(_ x: CodeUnit) -> Bool {
2730
return x & 0x80 == 0
2831
}
2932

33+
@inline(__always)
34+
@_inlineable
3035
public static func decode(_ source: EncodedScalar) -> UnicodeScalar {
3136
let bits = source._storage
3237
switch source._bitCount {
@@ -51,6 +56,8 @@ extension _Unicode.UTF8 : UnicodeEncoding {
5156
}
5257
}
5358

59+
@inline(__always)
60+
@_inlineable
5461
public static func encode(_ source: UnicodeScalar) -> EncodedScalar {
5562
var c = source.value
5663
if _fastPath(c < (1&<<7)) {
@@ -80,20 +87,25 @@ extension _Unicode.UTF8 : UnicodeEncoding {
8087

8188
public struct ForwardParser {
8289
public typealias _Buffer = _UIntBuffer<UInt32, UInt8>
90+
@inline(__always)
91+
@_inlineable
8392
public init() { _buffer = _Buffer() }
8493
public var _buffer: _Buffer
8594
}
8695

8796
public struct ReverseParser {
8897
public typealias _Buffer = _UIntBuffer<UInt32, UInt8>
98+
@inline(__always)
99+
@_inlineable
89100
public init() { _buffer = _Buffer() }
90101
public var _buffer: _Buffer
91102
}
92103
}
93104

94105
extension UTF8.ReverseParser : UnicodeParser, _UTFParser {
95106
public typealias Encoding = _Unicode.UTF8
96-
107+
@inline(__always)
108+
@_inlineable
97109
public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
98110
_sanityCheck(_buffer._storage & 0x80 != 0) // this case handled elsewhere
99111
if _buffer._storage & 0b0__1110_0000__1100_0000
@@ -128,6 +140,7 @@ extension UTF8.ReverseParser : UnicodeParser, _UTFParser {
128140
/// Returns the length of the invalid sequence that ends with the LSB of
129141
/// buffer.
130142
@inline(never)
143+
@_versioned
131144
func _invalidLength() -> UInt8 {
132145
if _buffer._storage & 0b0__1111_0000__1100_0000
133146
== 0b0__1110_0000__1000_0000 {
@@ -156,6 +169,8 @@ extension UTF8.ReverseParser : UnicodeParser, _UTFParser {
156169
return 1
157170
}
158171

172+
@inline(__always)
173+
@_inlineable
159174
public func _bufferedScalar(bitCount: UInt8) -> Encoding.EncodedScalar {
160175
return Encoding.EncodedScalar(
161176
_storage: _buffer._storage.byteSwapped &>> (32 - bitCount),
@@ -166,7 +181,9 @@ extension UTF8.ReverseParser : UnicodeParser, _UTFParser {
166181

167182
extension _Unicode.UTF8.ForwardParser : UnicodeParser, _UTFParser {
168183
public typealias Encoding = _Unicode.UTF8
169-
184+
185+
@inline(__always)
186+
@_inlineable
170187
public func _parseMultipleCodeUnits() -> (isValid: Bool, bitCount: UInt8) {
171188
_sanityCheck(_buffer._storage & 0x80 != 0) // this case handled elsewhere
172189

@@ -201,6 +218,7 @@ extension _Unicode.UTF8.ForwardParser : UnicodeParser, _UTFParser {
201218
/// Returns the length of the invalid sequence that starts with the LSB of
202219
/// buffer.
203220
@inline(never)
221+
@_versioned
204222
func _invalidLength() -> UInt8 {
205223
if _buffer._storage & 0b0__1100_0000__1111_0000
206224
== 0b0__1000_0000__1110_0000 {

stdlib/public/core/UnicodeParser.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ extension _Unicode {
7070
CodeUnitIterator : IteratorProtocol,
7171
Parser: UnicodeParser
7272
> where Parser.Encoding.CodeUnit == CodeUnitIterator.Element {
73+
@inline(__always)
74+
@_inlineable
7375
public init(codeUnits: CodeUnitIterator, parser: Parser) {
7476
self.codeUnits = codeUnits
7577
self.parser = parser
@@ -80,6 +82,8 @@ extension _Unicode {
8082
}
8183

8284
extension _Unicode.ParsingIterator : IteratorProtocol, Sequence {
85+
@inline(__always)
86+
@_inlineable
8387
public mutating func next() -> Parser.Encoding.EncodedScalar? {
8488
switch parser.parseScalar(from: &codeUnits) {
8589
case let .valid(scalarContent): return scalarContent

0 commit comments

Comments
 (0)