Skip to content

Commit

Permalink
leak in ResolvingQueryCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Aug 10, 2022
1 parent 1cae46d commit 86a13b3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Sources/SwiftTreeSitter/ResolvingQueryCursor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ public final class ResolvingQueryCursor {
private let cursor: QueryCursor
private var index: Array.Index
private var textProvider: TextProvider
private var cachedText: [NSRange : String]

public init(cursor: QueryCursor) {
self.cursor = cursor
self.matches = []
self.index = matches.startIndex
self.cachedText = [:]
self.textProvider = { _, _ in return nil }
}

Expand All @@ -37,17 +35,18 @@ public final class ResolvingQueryCursor {

public func prepare(with textProvider: @escaping TextProvider) {
self.index = matches.startIndex
self.cachedText.removeAll()

var cachedText = [NSRange : String]()

// create a caching provider
self.textProvider = { (range, pointRange) in
if let value = self.cachedText[range] {
if let value = cachedText[range] {
return value
}

let value = textProvider(range, pointRange)

self.cachedText[range] = value
cachedText[range] = value

return value
}
Expand Down

0 comments on commit 86a13b3

Please sign in to comment.