Skip to content

Commit

Permalink
Merge pull request #2703 from valeriyvan/RedundantZeroingJSONSerializ…
Browse files Browse the repository at this point in the history
…ation

Removes redundant buffer zeroing in JSONSerialization
  • Loading branch information
spevans committed Mar 6, 2020
2 parents e6c7a37 + 136a8a9 commit f98195d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Sources/Foundation/JSONSerialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ open class JSONSerialization : NSObject {
fatalError("Stream is not available for reading")
}
repeat {
var buffer = [UInt8](repeating: 0, count: 1024)
var bytesRead: Int = 0
bytesRead = stream.read(&buffer, maxLength: buffer.count)
if bytesRead < 0 {
throw stream.streamError!
} else {
data.append(&buffer, count: bytesRead)
let buffer = try [UInt8](unsafeUninitializedCapacity: 1024) { buf, initializedCount in
let bytesRead = stream.read(buf.baseAddress!, maxLength: buf.count)
initializedCount = bytesRead
guard bytesRead >= 0 else {
throw stream.streamError!
}
}
data.append(buffer, count: buffer.count)
} while stream.hasBytesAvailable
return try jsonObject(with: data, options: opt)
}
Expand Down

0 comments on commit f98195d

Please sign in to comment.