Skip to content

Commit e147601

Browse files
author
Wang Lun
committed
drop unnecessary change of cachedIndex
1 parent f509987 commit e147601

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Sources/SourceKitLSP/Swift/GeneratedInterfaceManager.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@ actor GeneratedInterfaceManager {
9292
incrementingRefCount: Bool
9393
) async throws -> OpenGeneratedInterfaceDocumentDetails {
9494
func loadFromCache() -> OpenGeneratedInterfaceDocumentDetails? {
95-
guard let cachedIndex = openInterfaces.firstIndex(where: { $0.url == document }) else {
95+
// Cache by module name and group name, not the full document data
96+
// This allows reuse across different buildSettingsFrom URIs
97+
guard let cachedIndex = openInterfaces.firstIndex(where: {
98+
$0.url.moduleName == document.moduleName &&
99+
$0.url.groupName == document.groupName &&
100+
$0.url.sourcekitdDocumentName == document.sourcekitdDocumentName
101+
}) else {
96102
return nil
97103
}
98104
if incrementingRefCount {
@@ -160,8 +166,11 @@ actor GeneratedInterfaceManager {
160166
}
161167

162168
private func decrementRefCount(for document: GeneratedInterfaceDocumentURLData) {
163-
guard let cachedIndex = openInterfaces.firstIndex(where: { $0.url == document }) else {
164-
logger.fault(
169+
guard let cachedIndex = openInterfaces.firstIndex(where: {
170+
$0.url.moduleName == document.moduleName &&
171+
$0.url.groupName == document.groupName &&
172+
$0.url.sourcekitdDocumentName == document.sourcekitdDocumentName
173+
}) else { logger.fault(
165174
"Generated interface document for \(document.moduleName) is not open anymore. Unbalanced retain and releases?"
166175
)
167176
return

0 commit comments

Comments
 (0)