From 0341fc1189df8b9d0de504317e58f1210612d0c4 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 22 Oct 2016 21:31:48 -0300 Subject: [PATCH] Reduce memory allocations for the SHA formats of love.math.hash. --HG-- branch : minor --- src/modules/math/HashFunction.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/modules/math/HashFunction.cpp b/src/modules/math/HashFunction.cpp index d7848625c..318b3bb4e 100644 --- a/src/modules/math/HashFunction.cpp +++ b/src/modules/math/HashFunction.cpp @@ -215,7 +215,7 @@ public: padded[paddedLength] = (length >> (56-i*8)) & 0xFF; // Allocate our extended words - uint32 *words = new uint32[80]; + uint32 words[80]; for (uint64 i = 0; i < paddedLength; i += 64) { @@ -264,7 +264,6 @@ public: intermediate[4] += E; } - delete[] words; delete[] padded; std::string hash(20, ' '); @@ -325,7 +324,7 @@ public: memcpy(intermediate, initial256, sizeof(intermediate)); // Allocate our extended words - uint32 *words = new uint32[64]; + uint32 words[64]; for (uint64 i = 0; i < paddedLength; i += 64) { @@ -382,8 +381,6 @@ public: intermediate[7] += H; } - - delete[] words; delete[] padded; int hashlength = 32; @@ -478,7 +475,7 @@ public: padded[paddedLength] = (length >> (56-i*8)) & 0xFF; // Allocate our extended words - uint64 *words = new uint64[80]; + uint64 words[80]; for (uint64 i = 0; i < paddedLength; i += 128) { @@ -538,7 +535,6 @@ public: intermediates[7] += H; } - delete[] words; delete[] padded; int hashlength = 64;