         switch encoding {
         case .utf8:
             yaml_parser_set_encoding(&parser, YAML_UTF8_ENCODING)
+            buffer = .utf8View(yaml.utf8)
+            if try yaml.utf8.withContiguousStorageIfAvailable(startParse(with:)) == nil {
             let utf8Slice = string.utf8CString.dropLast()
-            buffer = .utf8(utf8Slice)
+                buffer = .utf8Slice(utf8Slice)
             try utf8Slice.withUnsafeBytes(startParse(with:))
+            }
         case .utf16:
             // use native endian
             let isLittleEndian = 1 == 1.littleEndian

    private var parser = yaml_parser_t()

    private enum Buffer {
        case utf8(ArraySlice<CChar>)
        case utf16(Data)
    }
    private let buffer: Buffer
}

// MARK: Implementation Details

        try parse() // Drop YAML_STREAM_START_EVENT
    }

    func startParse(with buffer: UnsafeBufferPointer<UInt8>) throws {
        yaml_parser_set_input_string(&parser, buffer.baseAddress, buffer.count)
        try parse() // Drop YAML_STREAM_START_EVENT
    }

    @discardableResult
    func parse() throws -> Event {
        let event = Event()
