-
Notifications
You must be signed in to change notification settings - Fork 441
Add +=
operator for Trivia
#612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@swift-ci please test |
6932ed3
to
27c3404
Compare
@swift-ci please test |
Sources/SwiftSyntax/Trivia.swift.gyb
Outdated
/// Concatenates two collections of `Trivia` into the left-hand side. | ||
public func +=(lhs: inout Trivia, rhs: Trivia) { | ||
lhs = lhs + rhs | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a vague memory that from a type checking performance perspective, it’s better to implement these as static methods inside the Trivia
type itself.
/// Concatenates two collections of `Trivia` into the left-hand side. | |
public func +=(lhs: inout Trivia, rhs: Trivia) { | |
lhs = lhs + rhs | |
} | |
extension Trivia { | |
/// Concatenates two collections of `Trivia` into the left-hand side. | |
public static func +=(lhs: inout Trivia, rhs: Trivia) { | |
lhs = lhs + rhs | |
} | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this apply to the +
operator too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It used to, but we removed the designated types optimization that supported it. Now it should mostly a hygiene thing, and from that perspective I agree with Alex that this should be in extension context.
27c3404
to
3b1d6c8
Compare
@swift-ci please test |
A small convenience that makes it more convenient to construct
Trivia
imperatively.