Skip to content

Refactor operations to be on String #664

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

Merged
merged 14 commits into from
Apr 19, 2023
Merged
4 changes: 2 additions & 2 deletions Sources/RegexBenchmark/Utils/Stats.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Foundation
enum Stats {}

extension Stats {
// Maximum allowed standard deviation is 5% of the median runtime
static let maxAllowedStdev = 0.05
// Maximum allowed standard deviation is 7.5% of the median runtime
static let maxAllowedStdev = 0.075

static func tTest(_ a: Measurement, _ b: Measurement) -> Bool {
// Student's t-test
Expand Down
14 changes: 7 additions & 7 deletions Sources/_StringProcessing/Engine/MEBuiltins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Processor {
isStrictASCII: Bool,
isScalarSemantics: Bool
) -> Bool {
guard let next = input._matchBuiltinCC(
guard let next = input.matchBuiltinCC(
cc,
at: currentPosition,
isInverted: isInverted,
Expand Down Expand Up @@ -123,7 +123,7 @@ extension Processor {
extension String {
// TODO: Should the below have a `limitedBy` parameter?

func _matchAnyNonNewline(
func matchAnyNonNewline(
at currentPosition: String.Index,
isScalarSemantics: Bool
) -> String.Index? {
Expand All @@ -145,7 +145,7 @@ extension String {
}

@inline(__always)
func _quickMatchAnyNonNewline(
private func _quickMatchAnyNonNewline(
at currentPosition: String.Index,
isScalarSemantics: Bool
) -> QuickResult<String.Index?> {
Expand All @@ -165,7 +165,7 @@ extension String {
}

@inline(never)
func _thoroughMatchAnyNonNewline(
private func _thoroughMatchAnyNonNewline(
at currentPosition: String.Index,
isScalarSemantics: Bool
) -> String.Index? {
Expand All @@ -187,7 +187,7 @@ extension String {
// TODO: Should the below have a `limitedBy` parameter?

// Mentioned in ProgrammersManual.md, update docs if redesigned
func _matchBuiltinCC(
func matchBuiltinCC(
_ cc: _CharacterClassModel.Representation,
at currentPosition: String.Index,
isInverted: Bool,
Expand Down Expand Up @@ -222,7 +222,7 @@ extension String {

// Mentioned in ProgrammersManual.md, update docs if redesigned
@inline(__always)
func _quickMatchBuiltinCC(
private func _quickMatchBuiltinCC(
_ cc: _CharacterClassModel.Representation,
at currentPosition: String.Index,
isInverted: Bool,
Expand All @@ -240,7 +240,7 @@ extension String {

// Mentioned in ProgrammersManual.md, update docs if redesigned
@inline(never)
func _thoroughMatchBuiltinCC(
private func _thoroughMatchBuiltinCC(
_ cc: _CharacterClassModel.Representation,
at currentPosition: String.Index,
isInverted: Bool,
Expand Down
18 changes: 12 additions & 6 deletions Sources/_StringProcessing/Engine/MEQuantify.swift
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
extension Processor {
func _doQuantifyMatch(_ payload: QuantifyPayload) -> Input.Index? {
// FIXME: is the below updated for scalar semantics?
// TODO: This optimization is only enabled for grapheme cluster semantics,
// we want these for scalar semantics as well.

switch payload.type {
case .bitset:
return input.matchBitset(
registers[payload.bitset], at: currentPosition, limitedBy: end)
registers[payload.bitset],
at: currentPosition,
limitedBy: end,
isScalarSemantics: false)
case .asciiChar:
return input.matchScalar(
UnicodeScalar.init(_value: UInt32(payload.asciiChar)),
at: currentPosition,
limitedBy: end,
boundaryCheck: true)
boundaryCheck: true,
isCaseInsensitive: false)
case .builtin:
// FIXME: bounds check? endIndex or end?

// We only emit .quantify if it consumes a single character
return input._matchBuiltinCC(
return input.matchBuiltinCC(
payload.builtin,
at: currentPosition,
isInverted: payload.builtinIsInverted,
Expand All @@ -29,7 +35,7 @@ extension Processor {
return input.index(after: currentPosition)
}

return input._matchAnyNonNewline(
return input.matchAnyNonNewline(
at: currentPosition, isScalarSemantics: false)
}
}
Expand All @@ -41,7 +47,7 @@ extension Processor {
var trips = 0
var extraTrips = payload.extraTrips
var savePoint = startQuantifierSavePoint()

while true {
if trips >= payload.minTrips {
if extraTrips == 0 { break }
Expand Down
Loading