From ee5d3843e1e0c6c4bf04e287c5d23a448e6fba56 Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 5 Apr 2021 18:13:58 +0200 Subject: [PATCH] Memory optimization in CreateHash by using --- RDFSharp/Model/RDFModelUtilities.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/RDFSharp/Model/RDFModelUtilities.cs b/RDFSharp/Model/RDFModelUtilities.cs index 75517c88..57fb3725 100644 --- a/RDFSharp/Model/RDFModelUtilities.cs +++ b/RDFSharp/Model/RDFModelUtilities.cs @@ -35,18 +35,18 @@ public static class RDFModelUtilities #region Hashing /// - /// Performs MD5 hash calculation of the given string + /// Creates a unique long representation of the given string /// public static long CreateHash(string input) { - if (input != null) + if (input == null) + throw new RDFModelException("Cannot create hash because given \"input\" string parameter is null."); + + using (MD5CryptoServiceProvider md5Encryptor = new MD5CryptoServiceProvider()) { - var md5Encryptor = new MD5CryptoServiceProvider(); - var inputBytes = Encoding.UTF8.GetBytes(input); - var hashBytes = md5Encryptor.ComputeHash(inputBytes); + byte[] hashBytes = md5Encryptor.ComputeHash(Encoding.UTF8.GetBytes(input)); return BitConverter.ToInt64(hashBytes, 0); } - throw new RDFModelException("Cannot create hash because given \"input\" string parameter is null."); } #endregion