Skip to content

Commit

Permalink
Merge pull request #487 from till0xff/speedup-large-file-upload
Browse files Browse the repository at this point in the history
Improved performance of reading
  • Loading branch information
Vkt0r authored Nov 27, 2021
2 parents 2148628 + ef326c4 commit 1e4f51c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ All notable changes to this project will be documented in this file. Changes not
- Fix misspell `serialise`. ([#473](https://github.com/httpswift/swifter/pull/473)) by [@mtgto](https://github.com/mtgto)
- Fix an issue causing Danger was not working properly. ([#486](https://github.com/httpswift/swifter/pull/486)) by [@Vkt0r](https://github.com/Vkt0r)
- Set Swift version to 5.0 in podspec. ([#475](https://github.com/httpswift/swifter/pull/475)) by [@p-krasnobrovkin-tcs](https://github.com/p-krasnobrovkin-tcs)
- Improved performance of data reading. ([#487](https://github.com/httpswift/swifter/pull/487)) by [@till0xff](https://github.com/till0xff)

## Changed

Expand Down
10 changes: 3 additions & 7 deletions Xcode/Sources/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,9 @@ open class Socket: Hashable, Equatable {
/// - Returns: A buffer containing the bytes read
/// - Throws: SocketError.recvFailed if unable to read bytes from the socket
open func read(length: Int) throws -> [UInt8] {
var buffer = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: length)

let bytesRead = try read(into: &buffer, length: length)

let rv = [UInt8](buffer[0..<bytesRead])
buffer.deallocate()
return rv
return try [UInt8](unsafeUninitializedCapacity: length) { buffer, bytesRead in
bytesRead = try read(into: &buffer, length: length)
}
}

static let kBufferLength = 1024
Expand Down

0 comments on commit 1e4f51c

Please sign in to comment.