Skip to content

Commit 8b67405

Browse files
committed
Uses reduce(into:,_) instead of reduce(_,_) which gives an order of magnitude performance gain.
Tests on MacBook Pro 2018 (2,3 GHz Quad-Core Intel Core i5, RAM LPDDR3) show for array of random 100_000 elements: * original implementation 0.410 sec * proposed implementation 0.048 sec * also tried `lazy.map{ String(format: "%02x", $0) }.joined()` which takes 0.232 sec
1 parent e699ada commit 8b67405

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/CryptoSwift/Array+Extension.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ extension Array where Element == UInt8 {
6464
}
6565

6666
public func toHexString() -> String {
67-
`lazy`.reduce("") {
67+
`lazy`.reduce(into: "") {
6868
var s = String($1, radix: 16)
6969
if s.count == 1 {
7070
s = "0" + s
7171
}
72-
return $0 + s
72+
$0 += s
7373
}
7474
}
7575
}

0 commit comments

Comments
 (0)