Optimize [Data].flatCount
This commit is contained in:
parent
a861c69f36
commit
eb56a9a56c
|
@ -203,7 +203,7 @@ extension Data {
|
||||||
|
|
||||||
extension Array where Element == Data {
|
extension Array where Element == Data {
|
||||||
var flatCount: Int {
|
var flatCount: Int {
|
||||||
return map { $0.count }.reduce(0) { $0 + $1 }
|
return reduce(0) { $0 + $1.count }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,4 +72,14 @@ class DataManipulationTests: XCTestCase {
|
||||||
XCTAssertEqual(z2.toData(), Data(hex: "5678ab"))
|
XCTAssertEqual(z2.toData(), Data(hex: "5678ab"))
|
||||||
XCTAssertEqual(z3.toData(), Data(hex: "5678abaaddcc"))
|
XCTAssertEqual(z3.toData(), Data(hex: "5678abaaddcc"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testFlatCount() {
|
||||||
|
var v: [Data] = []
|
||||||
|
v.append(Data(hex: "11223344"))
|
||||||
|
v.append(Data(hex: "1122"))
|
||||||
|
v.append(Data(hex: "1122334455"))
|
||||||
|
v.append(Data(hex: "11223344556677"))
|
||||||
|
v.append(Data(hex: "112233"))
|
||||||
|
XCTAssertEqual(v.flatCount, 21)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue