Skip to content

Commit

Permalink
perf: make CharRefTokenizer non-copyable
Browse files Browse the repository at this point in the history
  • Loading branch information
kkebo committed Aug 13, 2024
1 parent a56809e commit 8a84bc4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Tokenizer/CharRefTokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum CharRefProcessResult: ~Copyable {
case doneChar(Char)
}

struct CharRefTokenizer {
struct CharRefTokenizer: ~Copyable {
private var state: CharRefState = .initial
private var num: Int = 0
private var numTooBig: Bool = false
Expand Down
7 changes: 7 additions & 0 deletions Sources/Tokenizer/Optional+take.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extension Optional where Wrapped: ~Copyable {
@inlinable mutating func take() -> Self {
let value = self
self = nil
return value
}
}
3 changes: 1 addition & 2 deletions Sources/Tokenizer/Tokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct Tokenizer<Sink: ~Copyable & TokenSink>: ~Copyable {
}

private mutating func step(_ input: inout BufferQueue) -> ProcessResult {
if var charRefTokenizer {
if var charRefTokenizer = self.charRefTokenizer.take() {
repeat {
switch charRefTokenizer.step(tokenizer: &self, input: &input) {
case .continue: continue
Expand All @@ -52,7 +52,6 @@ public struct Tokenizer<Sink: ~Copyable & TokenSink>: ~Copyable {
}
break
} while true
self.charRefTokenizer = nil
}

return switch self.state {
Expand Down

0 comments on commit 8a84bc4

Please sign in to comment.