-
Notifications
You must be signed in to change notification settings - Fork 222
Open
Description
I have dozen template and hundreds calls of Sorcery to generate the code, some of templates execute slowly and I try to find the issue. What I found, 150lines template spends 2+ sec to be loaded, after research I found an issue:
self.lines = zip(1..., templateString.components(separatedBy: .newlines)).compactMap { index, line in
guard !line.isEmpty,
let range = templateString.range(of: line) else { return nil }
return (content: line, number: UInt(index), range)
}Range(of) is not light operations, it scans origin text from the beginning on each step to find the current line.
I think we can improve it, as range(of:) does have additional param searchRange: Range<Self.Index>? = nil
So we can remember previous found range and use it to set searchRange
Metadata
Metadata
Assignees
Labels
No labels
