diff --git a/Sources/GATTClient.swift b/Sources/GATTClient.swift index b95735ef5..7f0785e0c 100755 --- a/Sources/GATTClient.swift +++ b/Sources/GATTClient.swift @@ -1057,7 +1057,7 @@ public final class GATTClient { // write next part let maxLength = Int(connection.maximumTransmissionUnit.rawValue) - ATTPrepareWriteRequest.length // 5 let endIndex = min(offset + maxLength, operation.data.count) - let attributeValuePart = operation.data.subdata(in: offset ..< endIndex) + let attributeValuePart = operation.data.subdataNoCopy(in: offset ..< endIndex) let pdu = ATTPrepareWriteRequest(handle: operation.lastRequest.handle, offset: UInt16(offset), diff --git a/Sources/GATTServer.swift b/Sources/GATTServer.swift index 007ea192b..3d8f6dec0 100644 --- a/Sources/GATTServer.swift +++ b/Sources/GATTServer.swift @@ -884,6 +884,7 @@ internal extension GATTDatabase { let handleRange = handle.end < UInt16.max ? Range(handle.start ... handle.end) : Range(handle.start ..< handle.end) var data: [(start: UInt16, end: UInt16, uuid: BluetoothUUID)] = [] + data.reserveCapacity(attributeGroups.count) for group in attributeGroups { @@ -893,7 +894,7 @@ internal extension GATTDatabase { guard groupRange.isSubset(handleRange) else { continue } - let serviceUUID = BluetoothUUID(littleEndian: BluetoothUUID(data: Data(group.serviceAttribute.value))!) + let serviceUUID = BluetoothUUID(littleEndian: BluetoothUUID(data: group.serviceAttribute.value)!) data.append((group.startHandle, group.endHandle, serviceUUID)) }