Skip to content

Commit ad88ccc

Browse files
authored
Refactored MD5Hash to use String.Concat and a single MD5 instance per call. (#605)
1 parent a02535d commit ad88ccc

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎src/FSharp.Data.GraphQL.Client/Extensions.fs‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ open System.Security.Cryptography
1111
/// Extensions for types used by the GraphQL client library.
1212
[<AutoOpen>]
1313
module internal Extensions =
14+
1415
type String with
1516
/// Returns the input string with the first character in upper case.
1617
member this.FirstCharUpper() =
@@ -20,11 +21,13 @@ module internal Extensions =
2021
member this.FirstCharLower() =
2122
this.Substring(0, 1).ToLowerInvariant() + this.Substring(1)
2223

23-
member this.MD5Hash() =
24-
Encoding.UTF8.GetBytes(this)
25-
|> MD5.Create().ComputeHash
24+
/// Returns a lowercase hex MD5 hash of the UTF-8 bytes of this string.
25+
member this.MD5Hash () =
26+
use md5 = MD5.Create()
27+
28+
md5.ComputeHash (Encoding.UTF8.GetBytes this)
2629
|> Seq.map _.ToString("x2")
27-
|> Seq.reduce (+)
30+
|> String.Concat
2831

2932
/// Basic operations on lists.
3033
module internal List =

0 commit comments

Comments
 (0)