-
Notifications
You must be signed in to change notification settings - Fork 49
Treat capture 0 (i.e. the whole match) specially #777
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
c9ffc99
to
5d7ff59
Compare
Perf improvement on top of #776:
|
@swift-ci please test |
var result = [AnyRegexOutput.ElementRepresentation]() | ||
|
||
for (i, (cap, meStored)) in zip(captures, list.values).enumerated() { | ||
result.append( |
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.
We should be able to reserve the correct capacity in result
before this…
result.append( | |
result.reserveCapacity(capList.captures.count) | |
result.append( |
if !cap.visibleInTypedOutput { | ||
fatalError("Why does this work?") | ||
} |
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.
Leftover?
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.
Hmm, I'm still not hitting that fatal error. Did you push the tests that should trigger it?
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.
Merged it!
guard typeErasedMatch is Output else { | ||
fatalError() | ||
} |
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.
This seems like it's doing the same thing as the as!
. Do we want a custom error message with the fatal error? Could rewrite as guard let output = typeErasedMatch...
if so.
5d7ff59
to
ffc9ce4
Compare
Rather than have the whole-match capture be a stored capture, we handle it specially. This speeds up processor resets as we do not need to reset a stored capture (especially when the regex has no other captures). It also speeds up the creation of save points and backtracking, as it's one less capture to save/restore.
ffc9ce4
to
1b77fb6
Compare
@swift-ci please test |
Rather than have the whole-match capture be a stored capture, we handle it specially. This speeds up processor resets as we do not need to reset a stored capture (especially when the regex has no other captures). It also speeds up the creation of save points and backtracking, as it's one less capture to save/restore.
Rather than have the whole-match capture be a stored capture, we handle it specially. This speeds up processor resets as we do not need to reset a stored capture (especially when the regex has no other captures).
It also speeds up the creation of save points and backtracking, as it's one less capture to save/restore.
Built on top of #776