Category talk:Wren-pattern: Difference between revisions

→‎Source code: Performance improvement for large strings.
(→‎Source code: Removed type aliases which are no longer needed.)
(→‎Source code: Performance improvement for large strings.)
Line 515:
 
// Private worker method.
// Looks for a pattern match forfrom thea stringlist of codepoints, 'scodes', starting from codepoint index 'start'.
// 'sc' is the number of codepoints in 'codes'.
// Returns a Match object if a match is found or null otherwise.
match_(scodes, start, sc) {
var tokens = _tokens.toList // use a copy as we might change it
var tc = tokens.count // tokens length
var ti = 0 // tokens index
var t = tokens[ti] // current token
var codes = s.codePoints.toList // string codepoints
var sc = s.count // string codepoints count
var si = start // string codepoints index
var c = -1 // string current codepoint
Line 844 ⟶ 843:
find(s) {
if (!(s is String)) Fiber.abort("Argument must be a string.")
var sccodes = s.countcodePoints.toList
var sc = scodes.count
if (sc < _minLen) return null
if (_type == Pattern.within) {
var maxStart = sc - _minLen
for (start in 0..maxStart) {
var m = match_(scodes, start, sc)
if (m) return m
}
return null
}
if (_type == Pattern.start) return match_(scodes, 0, sc)
if (_type == Pattern.end) {
var maxStart = sc - _minLen
for (start in 0..maxStart) {
var m = match_(scodes, start, sc)
if (m && ((start + m.length) == sc)) return m
}
Line 864:
}
if (_type == Pattern.whole) {
var m = match_(scodes, 0, sc)
if (!m || m.length < sc) return null
return m
Line 880:
}
if (!m) return []
var sc = s.count
var matches = [m]
if (m.length == 0) return matches
var codes = s.codePoints.toList // string codepoints
var sc = codes.count
var start = m.index + m.length
while (start + _minLen <= sc) {
m = match_(scodes, start, sc)
if (m) {
matches.add(m)
9,476

edits