Skip to content

Commit

Permalink
Paywalls: avoid recomputing variable Regex (#2944)
Browse files Browse the repository at this point in the history
See #2811.
It's unclear from the docs whether this is a performance optimization,
but at least it's a nice refactor.
  • Loading branch information
NachoSoto committed Aug 7, 2023
1 parent 658a182 commit 7c3656b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions RevenueCatUI/Data/Variables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,7 @@ enum VariableHandler {
}

private static func extractVariables(from expression: String) -> [VariableMatch] {
let variablePattern = Regex {
OneOrMore {
"{{ "
Capture {
OneOrMore(.word)
}
" }}"
}
}

return expression.matches(of: variablePattern).map { match in
return expression.matches(of: Self.regex).map { match in
let (_, variable) = match.output
return VariableMatch(variable: String(variable), range: match.range)
}
Expand All @@ -71,6 +61,16 @@ enum VariableHandler {

}

private static let regex = Regex {
OneOrMore {
"{{ "
Capture {
OneOrMore(.word)
}
" }}"
}
}

}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
Expand Down

0 comments on commit 7c3656b

Please sign in to comment.