Skip to content

Commit 630ff88

Browse files
committed
Speed up parsing
1 parent c01667d commit 630ff88

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

Sources/BinaryParseKit/Utils/ParsingUtils.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import BinaryParsing
88

99
/// Matches the given bytes in the input parser span.
1010
/// - Warning: This function is used by `@ParseEnum` macro and should not be used directly.
11-
@inline(__always)
11+
@inlinable
1212
public func __match(_ bytes: borrowing [UInt8], in input: borrowing BinaryParsing.ParserSpan) -> Bool {
1313
if bytes.isEmpty { return true }
1414

@@ -28,41 +28,41 @@ public func __match(_ bytes: borrowing [UInt8], in input: borrowing BinaryParsin
2828

2929
/// Matches when the remaining bytes in the input parser span equals the specified length.
3030
/// - Warning: This function is used by `@ParseEnum` macro and should not be used directly.
31-
@inline(__always)
31+
@inlinable
3232
public func __match(length: Int, in input: borrowing BinaryParsing.ParserSpan) -> Bool {
3333
input.count == length
3434
}
3535

3636
/// Asserts that the given type conforms to `Parsable`.
3737
/// - Warning: This function is used to `@parse` macro and should not be used directly.
38-
@inline(__always)
38+
@inlinable
3939
public func __assertParsable(_: (some Parsable).Type) {}
4040

4141
/// Asserts that the given type conforms to `SizedParsable`.
4242
/// - Warning: This function is used to `@parse` macro and should not be used directly.
43-
@inline(__always)
43+
@inlinable
4444
public func __assertSizedParsable(_: (some SizedParsable).Type) {}
4545

4646
/// Asserts that the given type conforms to `EndianParsable`.
4747
/// - Warning: This function is used to `@parse` macro and should not be used directly.
48-
@inline(__always)
48+
@inlinable
4949
public func __assertEndianParsable(_: (some EndianParsable).Type) {}
5050

5151
/// Asserts that the given type conforms to `EndianSizedParsable`.
5252
/// - Warning: This function is used to `@parse` macro and should not be used directly.
53-
@inline(__always)
53+
@inlinable
5454
public func __assertEndianSizedParsable(_: (some EndianSizedParsable).Type) {}
5555

5656
// MARK: - Bitmask Parsing Utilities
5757

5858
/// Asserts that the given type conforms to `BitmaskParsable`.
5959
/// - Warning: This function is used by `@mask()` macro and should not be used directly.
60-
@inline(__always)
60+
@inlinable
6161
public func __assertBitmaskParsable(_: (some ExpressibleByRawBits & BitCountProviding).Type) {}
6262

6363
/// Asserts that the given type conforms to `ExpressibleByRawBits`.
6464
/// - Warning: This function is used by `@mask(bitCount:)` macro and should not be used directly.
65-
@inline(__always)
65+
@inlinable
6666
public func __assertExpressibleByRawBits(_: (some ExpressibleByRawBits).Type) {}
6767

6868
/// Extracts bits from a ParserSpan and returns them as a right-aligned FixedWidthInteger.
@@ -82,7 +82,7 @@ public func __assertExpressibleByRawBits(_: (some ExpressibleByRawBits).Type) {}
8282
/// - Right-aligned result: 0b0000_0011 = 3
8383
/// - Warning: This function is used by bitmask macros and should not be used directly.
8484
/// - Important: `input` but have at least `(offset + count + 7) / 8` bytes available.
85-
@inline(__always)
85+
@inlinable
8686
func __extractBitsAsInteger<I: FixedWidthInteger>(
8787
_: I.Type,
8888
from input: borrowing BinaryParsing.ParserSpan,
@@ -148,7 +148,7 @@ func __extractBitsAsInteger<I: FixedWidthInteger>(
148148

149149
/// Asserts that the given type conforms to `RawBitsConvertible` and `BitCountProviding`.
150150
/// - Warning: This function is used by `@ParseBitmask` macro and should not be used directly.
151-
@inline(__always)
151+
@inlinable
152152
public func __assertRawBitsConvertible(_: (some RawBitsConvertible & BitCountProviding).Type) {}
153153

154154
/// Converts a value to RawBits with the specified bit count.
@@ -158,7 +158,7 @@ public func __assertRawBitsConvertible(_: (some RawBitsConvertible & BitCountPro
158158
/// - bitCount: The number of bits to produce
159159
/// - Returns: The raw bits representation
160160
/// - Throws: An error if the conversion cannot be performed
161-
@inline(__always)
161+
@inlinable
162162
public func __toRawBits(
163163
_ value: some RawBitsConvertible,
164164
bitCount: Int,
@@ -169,7 +169,7 @@ public func __toRawBits(
169169
// MARK: - Bit Adjustment Utilities for @mask(bitCount:)
170170

171171
/// Overload for types that also conform to BitCountProviding - handles bit count validation and adjustment.
172-
@inline(__always)
172+
@inlinable
173173
func __createFromBits<T: ExpressibleByRawBits & BitCountProviding>(
174174
_: T.Type,
175175
fieldBits: some FixedWidthInteger,
@@ -188,7 +188,7 @@ func __createFromBits<T: ExpressibleByRawBits & BitCountProviding>(
188188
}
189189

190190
/// Fallback overload for types that only conform to ExpressibleByRawBits.
191-
@inline(__always)
191+
@inlinable
192192
func __createFromBits<T: ExpressibleByRawBits>(
193193
_: T.Type,
194194
fieldBits: some FixedWidthInteger,
@@ -197,7 +197,7 @@ func __createFromBits<T: ExpressibleByRawBits>(
197197
try T(bits: T.RawBitsInteger(truncatingIfNeeded: fieldBits))
198198
}
199199

200-
@inline(__always)
200+
@inlinable
201201
public func __maskParsing<Parent: ExpressibleByRawBits, Field: ExpressibleByRawBits>(
202202
from bits: Parent.RawBitsInteger,
203203
parentType: Parent.Type,
@@ -206,13 +206,13 @@ public func __maskParsing<Parent: ExpressibleByRawBits, Field: ExpressibleByRawB
206206
at bitPosition: Int,
207207
) throws -> Field {
208208
let shift = parentType.RawBitsInteger.bitWidth - bitPosition - fieldRequestedBitCount
209-
let mask = parentType.RawBitsInteger((1 << fieldRequestedBitCount) - 1)
210-
let fieldBits = (bits >> shift) & mask
209+
let mask: Parent.RawBitsInteger = (1 << fieldRequestedBitCount) - 1
210+
let fieldBits: Parent.RawBitsInteger = (bits >> shift) & mask
211211

212212
return try __createFromBits(fieldType, fieldBits: fieldBits, fieldRequestedBitCount: fieldRequestedBitCount)
213213
}
214214

215-
@inline(__always)
215+
@inlinable
216216
public func __maskParsing<Field: ExpressibleByRawBits>(
217217
from span: borrowing BinaryParsing.ParserSpan,
218218
fieldType: Field.Type,

0 commit comments

Comments
 (0)