1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 03:25:03 +03:00

Refactor slightly

This commit is contained in:
Tae Won Ha 2020-02-11 07:37:07 +01:00
parent 911aea2ae3
commit 4bb04b4ed1
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -134,8 +134,9 @@ final class Typesetter {
return runs.flatMap { $0 }
}
private let log = OSLog(subsystem: Defs.loggerSubsystem,
category: Defs.LoggerCategory.view)
private let ctRunsCache = SimpleCache<NSAttributedString, [CTRun]>(countLimit: 5000)
private let log = OSLog(subsystem: Defs.loggerSubsystem, category: Defs.LoggerCategory.view)
private func ctRuns(from utf16Chars: Array<Unicode.UTF16.CodeUnit>, font: NSFont) -> [CTRun] {
let attrStr = NSAttributedString(
@ -143,12 +144,12 @@ final class Typesetter {
attributes: [.font: font, .ligature: NSNumber(integerLiteral: 1)]
)
if let cachedCtRuns = ctRunsCache.object(forKey: attrStr) { return cachedCtRuns }
if let cachedCtRuns = self.ctRunsCache.object(forKey: attrStr) { return cachedCtRuns }
let ctLine = CTLineCreateWithAttributedString(attrStr)
guard let ctRuns = CTLineGetGlyphRuns(ctLine) as? [CTRun] else { return [] }
ctRunsCache.set(object: ctRuns, forKey: attrStr)
self.ctRunsCache.set(object: ctRuns, forKey: attrStr)
return ctRuns
}
@ -275,5 +276,3 @@ final class Typesetter {
}
}
}
private let ctRunsCache = SimpleCache<NSAttributedString, [CTRun]>(countLimit: 20000)