Skip to content

Commit 3b715da

Browse files
committed
[SyntaxParser] Simpify a bit how we get the source text string from a file, NFC
1 parent e7bcc57 commit 3b715da

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

Sources/SwiftSyntax/SyntaxParser.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ public enum SyntaxParser {
106106
public static func parse(_ url: URL,
107107
diagnosticEngine: DiagnosticEngine? = nil) throws -> SourceFileSyntax {
108108
// Avoid using `String(contentsOf:)` because it creates a wrapped NSString.
109-
var fileData = try Data(contentsOf: url)
110-
fileData.append(0) // null terminate.
111-
let source = fileData.withUnsafeBytes { (ptr: UnsafePointer<CChar>) in
112-
return String(cString: ptr)
109+
let fileData = try Data(contentsOf: url)
110+
let source = fileData.withUnsafeBytes { buf in
111+
return String.fromBuffer(buf.bindMemory(to: UInt8.self))
113112
}
114113
return try parse(source: source, filenameForDiagnostics: url.absoluteString,
115114
diagnosticEngine: diagnosticEngine)

0 commit comments

Comments
 (0)