From b20ecfc6fc82b818b6048eaa02a4a15ff597235e Mon Sep 17 00:00:00 2001 From: Valerii Iamkovyi Date: Fri, 25 Oct 2024 11:52:02 -0500 Subject: [PATCH] TDA-3417: func dequeueInput was refactored, removed unneeded conversion to NSData --- .../DefaultImplementation/WebSocket.swift | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Sources/ApolloWebSocket/DefaultImplementation/WebSocket.swift b/Sources/ApolloWebSocket/DefaultImplementation/WebSocket.swift index 465421dd1c..c6ea4b2ec2 100644 --- a/Sources/ApolloWebSocket/DefaultImplementation/WebSocket.swift +++ b/Sources/ApolloWebSocket/DefaultImplementation/WebSocket.swift @@ -585,28 +585,31 @@ open class WebSocket: NSObject, WebSocketClient, StreamDelegate, WebSocketStream /** Dequeue the incoming input so it is processed in order. */ - private func dequeueInput() { - while !inputQueue.isEmpty { - autoreleasepool { - let data = inputQueue[0] - var work = data - if let buffer = fragBuffer { - var combine = NSData(data: buffer) as Data - combine.append(data) - work = combine - fragBuffer = nil - } - let buffer = UnsafeRawPointer((work as NSData).bytes).assumingMemoryBound(to: UInt8.self) - let length = work.count - if !connected { - processTCPHandshake(buffer, bufferLen: length) - } else { - processRawMessagesInBuffer(buffer, bufferLen: length) + private func dequeueInput() { + while !inputQueue.isEmpty { + autoreleasepool { + let data = inputQueue[0] + var work = data + if let buffer = fragBuffer { + var combine = buffer + combine.append(data) + work = combine + fragBuffer = nil + } + work.withUnsafeBytes { (buffer: UnsafeRawBufferPointer) in + if let baseAddress = buffer.baseAddress?.assumingMemoryBound(to: UInt8.self) { + let length = work.count + if !connected { + processTCPHandshake(baseAddress, bufferLen: length) + } else { + processRawMessagesInBuffer(baseAddress, bufferLen: length) + } + } + } + inputQueue.removeFirst() + } } - inputQueue = inputQueue.filter{ $0 != data } - } } - } /** Handle checking the inital connection status