This is an automated email from the ASF dual-hosted git repository. lostluck pushed a commit to branch swift-sdk in repository https://gitbox.apache.org/repos/asf/beam.git
commit 28268f78874d5ff6b35ab94683da629ef77503cb Author: Byron Ellis <[email protected]> AuthorDate: Thu Aug 17 11:46:19 2023 -0700 Use a single advance in varint implementation --- sdks/swift/Sources/ApacheBeam/Internal/Data+Decoding.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sdks/swift/Sources/ApacheBeam/Internal/Data+Decoding.swift b/sdks/swift/Sources/ApacheBeam/Internal/Data+Decoding.swift index 706c2036cbf..aa6b31bf35b 100644 --- a/sdks/swift/Sources/ApacheBeam/Internal/Data+Decoding.swift +++ b/sdks/swift/Sources/ApacheBeam/Internal/Data+Decoding.swift @@ -20,12 +20,12 @@ import Foundation extension Data { /// Read a variable length integer from the current data mutating func varint() throws -> Int { - var data = self - let result = try data.withUnsafeBytes { + var advance: Int = 0 + let result = try self.withUnsafeBytes { try $0.baseAddress!.withMemoryRebound(to: UInt8.self, capacity: 4) { var p = $0 if(p.pointee & 0x80 == 0) { - data = data.advanced(by: 1) + advance += 1 return Int(UInt64(p.pointee)) } var value = UInt64(p.pointee & 0x7f) @@ -39,7 +39,7 @@ extension Data { count += 1 value |= UInt64(p.pointee & 0x7f) << shift if(p.pointee & 0x80 == 0) { - data = data.advanced(by: count) + advance += count return Int(value) } p = p.successor() @@ -47,7 +47,7 @@ extension Data { } } } - self = data + self = self.advanced(by: advance) return result }
