Skip to content

Commit

Permalink
Replace __owned with consuming
Browse files Browse the repository at this point in the history
  • Loading branch information
kkebo committed Aug 27, 2023
1 parent f879f5e commit e81ebc8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Benchmarks/Benchmarks/MyBenchmark/MyBenchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct TestSink {
}

extension TestSink: TokenSink {
mutating func process(_ token: __owned Token) {
mutating func process(_ token: consuming Token) {
self.tokens.append(consume token)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tokenizer/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ public struct Attribute {
public var name: String
public var value: String

public init(name: __owned String, value: __owned String) {
public init(name: consuming String, value: consuming String) {
self.name = consume name
self.value = consume value
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Tokenizer/DOCTYPE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ public struct DOCTYPE {
public var forceQuirks: Bool

public init(
name: __owned Optional<String> = nil,
forceQuirks: __owned Bool = false
name: consuming Optional<String> = nil,
forceQuirks: consuming Bool = false
) {
self.name = consume name
self.forceQuirks = consume forceQuirks
Expand Down
8 changes: 4 additions & 4 deletions Sources/Tokenizer/Tag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ public struct Tag {
public var selfClosing: Bool

public init(
name: __owned String,
kind: __owned TagKind,
attrs: __owned [Attribute] = [],
selfClosing: __owned Bool = false
name: consuming String,
kind: consuming TagKind,
attrs: consuming [Attribute] = [],
selfClosing: consuming Bool = false
) {
self.name = consume name
self.kind = consume kind
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tokenizer/TokenSink.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
public protocol TokenSink {
mutating func process(_ token: __owned Token)
mutating func process(_ token: consuming Token)
}
38 changes: 19 additions & 19 deletions Sources/Tokenizer/Tokenizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {
var currentComment: String
var currentDOCTYPE: DOCTYPE

public init(sink: __owned Sink) {
public init(sink: consuming Sink) {
self.sink = consume sink
self.state = .data
self.reconsumeChar = nil
Expand Down Expand Up @@ -484,7 +484,7 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {

private mutating func startsExact(
_ input: inout String.Iterator,
with pattern: __owned some StringProtocol
with pattern: consuming some StringProtocol
) -> Bool? {
let initial = input
for pc in consume pattern {
Expand All @@ -502,7 +502,7 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {

private mutating func starts(
_ input: inout String.Iterator,
with pattern: __owned some StringProtocol
with pattern: consuming some StringProtocol
) -> Bool? {
let initial = input
for pc in consume pattern {
Expand All @@ -519,12 +519,12 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {
}

@inline(__always)
private mutating func go(to state: __owned State) {
private mutating func go(to state: consuming State) {
self.state = consume state
}

@inline(__always)
private mutating func go(reconsume c: __owned Character, to state: __owned State) {
private mutating func go(reconsume c: consuming Character, to state: consuming State) {
self.reconsumeChar = consume c
self.state = consume state
}
Expand All @@ -535,47 +535,47 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {
}

@inline(__always)
private mutating func createComment(with c: __owned Character) {
private mutating func createComment(with c: consuming Character) {
self.currentComment = String(consume c)
}

@_disfavoredOverload
@inline(__always)
private mutating func createComment(with s: __owned String) {
private mutating func createComment(with s: consuming String) {
self.currentComment = consume s
}

@inline(__always)
private mutating func createStartTag(with s: __owned String) {
private mutating func createStartTag(with s: consuming String) {
self.currentTagName = consume s
self.currentTagKind = .start
self.currentAttrs.removeAll()
}

@inline(__always)
private mutating func createEndTag(with c: __owned Character) {
private mutating func createEndTag(with c: consuming Character) {
self.currentTagName = String(consume c)
self.currentTagKind = .end
self.currentAttrs.removeAll()
}

@_disfavoredOverload
@inline(__always)
private mutating func createEndTag(with s: __owned String) {
private mutating func createEndTag(with s: consuming String) {
self.currentTagName = consume s
self.currentTagKind = .end
self.currentAttrs.removeAll()
}

@inline(__always)
private mutating func createAttr(with c: __owned Character) {
private mutating func createAttr(with c: consuming Character) {
self.pushAttr()
self.currentAttrName = String(consume c)
}

@_disfavoredOverload
@inline(__always)
private mutating func createAttr(with s: __owned String) {
private mutating func createAttr(with s: consuming String) {
self.pushAttr()
self.currentAttrName = consume s
}
Expand All @@ -594,18 +594,18 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {
}

@inline(__always)
private mutating func createDOCTYPE(with c: __owned Character) {
private mutating func createDOCTYPE(with c: consuming Character) {
self.currentDOCTYPE = .init(name: String(consume c))
}

@_disfavoredOverload
@inline(__always)
private mutating func createDOCTYPE(with s: __owned String) {
private mutating func createDOCTYPE(with s: consuming String) {
self.currentDOCTYPE = .init(name: consume s)
}

@inline(__always)
private mutating func appendDOCTYPEName(_ c: __owned Character) {
private mutating func appendDOCTYPEName(_ c: consuming Character) {
switch self.currentDOCTYPE.name {
case .some: self.currentDOCTYPE.name?.append(consume c)
case .none: self.currentDOCTYPE.name = String(consume c)
Expand All @@ -614,7 +614,7 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {

@_disfavoredOverload
@inline(__always)
private mutating func appendDOCTYPEName(_ s: __owned String) {
private mutating func appendDOCTYPEName(_ s: consuming String) {
switch self.currentDOCTYPE.name {
case .some: self.currentDOCTYPE.name?.append(consume s)
case .none: self.currentDOCTYPE.name = consume s
Expand All @@ -627,7 +627,7 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {
}

@inline(__always)
private mutating func emitError(_ error: __owned ParseError) {
private mutating func emitError(_ error: consuming ParseError) {
self.sink.process(.error(consume error))
}

Expand All @@ -637,13 +637,13 @@ public struct Tokenizer<Sink: TokenSink>: ~Copyable {
}

@inline(__always)
private mutating func emit(_ c: __owned Character) {
private mutating func emit(_ c: consuming Character) {
self.sink.process(.char(consume c))
}

@_disfavoredOverload
@inline(__always)
private mutating func emit(_ token: __owned Token) {
private mutating func emit(_ token: consuming Token) {
self.sink.process(consume token)
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/TokenizerTests/TokenizerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct TestSink {
}

extension TestSink: TokenSink {
mutating func process(_ token: __owned Token) {
mutating func process(_ token: consuming Token) {
self.tokens.append(consume token)
}
}
Expand Down

0 comments on commit e81ebc8

Please sign in to comment.