Skip to content

Commit 187b938

Browse files
authored
Some small cleanups. (#1773)
- Make things that never need to mutate explicit `let`s so intent is clear. - Simplify `complete`, guess this used to actually mutate, but it doesn't anymore. - The `_NameMap` is always found or `init` fails, so no need for it to be `Optional` and thus no need to force unwrap it.
1 parent 1589dc3 commit 187b938

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

Sources/SwiftProtobuf/TextFormatDecoder.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,15 @@ import Foundation
2323
internal struct TextFormatDecoder: Decoder {
2424
internal var scanner: TextFormatScanner
2525
private var fieldCount = 0
26-
private var terminator: UInt8?
27-
private var fieldNameMap: _NameMap?
28-
private var messageType: any Message.Type
26+
private let terminator: UInt8?
27+
private let fieldNameMap: _NameMap
28+
private let messageType: any Message.Type
2929

3030
internal var options: TextFormatDecodingOptions {
3131
scanner.options
3232
}
3333

34-
internal var complete: Bool {
35-
mutating get {
36-
scanner.complete
37-
}
38-
}
34+
internal var complete: Bool { scanner.complete }
3935

4036
internal init(
4137
messageType: any Message.Type,
@@ -50,6 +46,7 @@ internal struct TextFormatDecoder: Decoder {
5046
}
5147
fieldNameMap = nameProviding._protobuf_nameMap
5248
self.messageType = messageType
49+
self.terminator = nil
5350
}
5451

5552
internal init(messageType: any Message.Type, scanner: TextFormatScanner, terminator: UInt8?) throws {
@@ -71,7 +68,7 @@ internal struct TextFormatDecoder: Decoder {
7168
scanner.skipOptionalSeparator()
7269
}
7370
if let fieldNumber = try scanner.nextFieldNumber(
74-
names: fieldNameMap!,
71+
names: fieldNameMap,
7572
messageType: messageType,
7673
terminator: terminator
7774
) {

Sources/SwiftProtobuf/TextFormatScanner.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,15 @@ private func decodeString(_ s: String) -> String? {
240240
/// TextFormatScanner has no public members.
241241
///
242242
internal struct TextFormatScanner {
243-
internal var extensions: (any ExtensionMap)?
243+
internal let extensions: (any ExtensionMap)?
244244
private var p: UnsafeRawPointer
245-
private var end: UnsafeRawPointer
246-
private var doubleParser = DoubleParser()
245+
private let end: UnsafeRawPointer
246+
private let doubleParser = DoubleParser()
247247

248248
internal let options: TextFormatDecodingOptions
249249
internal var recursionBudget: Int
250250

251-
internal var complete: Bool {
252-
mutating get {
253-
p == end
254-
}
255-
}
251+
internal var complete: Bool { p == end }
256252

257253
internal init(
258254
utf8Pointer: UnsafeRawPointer,

0 commit comments

Comments
 (0)