Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions Sources/TOMLDecoder/Parsing/TOMLDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,27 @@ struct TOMLDocument: Equatable, @unchecked Sendable {
let source: String

init(source: String, keyTransform: (@Sendable (String) -> String)?) throws(TOMLError) {
var source = source
var hasContinousStorage = false
var parser = Parser(keyTransform: keyTransform)

do {
try source.withUTF8 { try parser.parse(bytes: $0) }
try source.utf8.withContiguousStorageIfAvailable {
hasContinousStorage = true
try parser.parse(bytes: $0)
}
} catch {
throw error as! TOMLError
}

if !hasContinousStorage {
var source = source
do {
try source.withUTF8 { try parser.parse(bytes: $0) }
} catch {
throw error as! TOMLError
}
}

self.source = source
tables = parser.tables
arrays = parser.arrays
Expand Down
Loading