diff --git a/Sources/PostgresNIO/Data/PostgresData+Numeric.swift b/Sources/PostgresNIO/Data/PostgresData+Numeric.swift index 5e564d6d..ded3135c 100644 --- a/Sources/PostgresNIO/Data/PostgresData+Numeric.swift +++ b/Sources/PostgresNIO/Data/PostgresData+Numeric.swift @@ -251,36 +251,26 @@ extension PostgresData { } private extension Collection { - // splits the collection into chunks of the supplied size - // if the collection is not evenly divisible, the last chunk will be smaller + /// Split the collection into chunks of `maxSize` length each. The last chunk may contain anywhere between 1 and maxSize elements. `maxSize` must be greater than zero. func chunked(by maxSize: Int) -> [SubSequence] { - return stride(from: 0, to: self.count, by: maxSize).map { current in - let chunkStartIndex = self.index(self.startIndex, offsetBy: current) - let chunkEndOffset = Swift.min( - self.distance(from: chunkStartIndex, to: self.endIndex), - maxSize - ) - let chunkEndIndex = self.index(chunkStartIndex, offsetBy: chunkEndOffset) - return self[chunkStartIndex.. [SubSequence] { - var lastDistance = 0 - var chunkStartIndex = self.startIndex - return stride(from: 0, to: self.count, by: maxSize).reversed().map { current in - let distance = (self.count - current) - lastDistance - lastDistance = distance - let chunkEndOffset = Swift.min( - self.distance(from: chunkStartIndex, to: self.endIndex), - distance - ) - let chunkEndIndex = self.index(chunkStartIndex, offsetBy: chunkEndOffset) - defer { chunkStartIndex = chunkEndIndex } - return self[chunkStartIndex..