Skip to content

Commit

Permalink
#104 Optimized data parsing to reuse data buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Aug 25, 2018
1 parent a5e0106 commit c06c278
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/GATTClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion Sources/GATTServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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))
}
Expand Down

0 comments on commit c06c278

Please sign in to comment.