Skip to content

Commit 2f337ec

Browse files
authored
Don't allocate when calculating the digest of code (#692)
1 parent 2ab9c63 commit 2f337ec

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ClearScript/Util/MiscHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static uint GetDigestAsUInt32(this string code)
246246

247247
unchecked
248248
{
249-
var bytes = Encoding.Unicode.GetBytes(code);
249+
var bytes = MemoryMarshal.AsBytes(code.AsSpan());
250250
for (var index = 0; index < bytes.Length; index++)
251251
{
252252
digest ^= bytes[index];
@@ -262,7 +262,7 @@ public static ulong GetDigestAsUInt64(this string code)
262262
var digest = 14695981039346656037UL;
263263
const ulong prime = 1099511628211UL;
264264

265-
var bytes = Encoding.Unicode.GetBytes(code);
265+
var bytes = MemoryMarshal.AsBytes(code.AsSpan());
266266
for (var index = 0; index < bytes.Length; index++)
267267
{
268268
digest ^= bytes[index];

0 commit comments

Comments
 (0)