Skip to content

Commit e456bba

Browse files
committed
[DiagnosticBridge] NFC: Switch to use String(bridged:) instead of String(decoding:as:)
1 parent ac91d39 commit e456bba

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

lib/ASTGen/Sources/ASTGen/DiagnosticsBridge.swift

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -348,57 +348,37 @@ public func addQueuedDiagnostic(
348348
}
349349
}
350350

351-
let category: DiagnosticCategory? = categoryName.data.flatMap { categoryNamePtr in
352-
let categoryNameBuffer = UnsafeBufferPointer(
353-
start: categoryNamePtr,
354-
count: categoryName.count
355-
)
356-
let categoryName = String(decoding: categoryNameBuffer, as: UTF8.self)
357-
358-
// If the data comes from serialized diagnostics, it's possible that
359-
// the category name is empty because StringRef() is serialized into
360-
// an empty string.
361-
guard !categoryName.isEmpty else {
362-
return nil
351+
let documentationPath = String(bridged: documentationPath)
352+
let documentationURL: String? = if !documentationPath.isEmpty {
353+
// If this looks doesn't look like a URL, prepend file://.
354+
documentationPath.looksLikeURL ? documentationPath : "file://\(documentationPath)"
355+
} else {
356+
nil
363357
}
364358

365-
let documentationURL = documentationPath.data.map { documentationPathPtr in
366-
let documentationPathBuffer = UnsafeBufferPointer(
367-
start: documentationPathPtr,
368-
count: documentationPath.count
359+
let categoryName = String(bridged: categoryName)
360+
// If the data comes from serialized diagnostics, it's possible that
361+
// the category name is empty because StringRef() is serialized into
362+
// an empty string.
363+
let category: DiagnosticCategory? = if !categoryName.isEmpty {
364+
DiagnosticCategory(
365+
name: categoryName,
366+
documentationURL: documentationURL
369367
)
370-
371-
let documentationPath = String(decoding: documentationPathBuffer, as: UTF8.self)
372-
373-
// If this looks doesn't look like a URL, prepend file://.
374-
if !documentationPath.looksLikeURL {
375-
return "file://\(documentationPath)"
376-
}
377-
378-
return documentationPath
368+
} else {
369+
nil
379370
}
380371

381-
return DiagnosticCategory(
382-
name: categoryName,
383-
documentationURL: documentationURL
384-
)
385-
}
386-
387372
// Note that we referenced this category.
388373
if let category {
389374
diagnosticState.pointee.referencedCategories.insert(category)
390375
}
391376

392-
guard let textPtr = text.data, !text.isEmpty else {
393-
return
394-
}
395-
396-
let textBuffer = UnsafeBufferPointer(start: textPtr, count: text.count)
397377
let diagnostic = Diagnostic(
398378
node: node,
399379
position: position,
400380
message: SimpleDiagnostic(
401-
message: String(decoding: textBuffer, as: UTF8.self),
381+
message: String(bridged: text),
402382
severity: severity.asSeverity,
403383
category: category
404384
),

0 commit comments

Comments
 (0)