From 425acc5de5bda37e2152ba79058cf9d5e7ef021e Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Mon, 18 Sep 2023 14:48:24 -0400 Subject: [PATCH] avoid some allocations 2015 was allocating over 2gb memory in small object heap for the md5 byte conversions --- AOC2015/Day04.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AOC2015/Day04.cs b/AOC2015/Day04.cs index 57fcc12..cad07cb 100644 --- a/AOC2015/Day04.cs +++ b/AOC2015/Day04.cs @@ -33,12 +33,12 @@ public sealed class Day04 : Day public override object Part2() { - var counter = 0; + var counter = 9_000_000; while (true) { - var hash = MD5.HashData(Encoding.ASCII.GetBytes(_key + counter)); - if (BitConverter.ToString(hash).Replace("-", "").StartsWith("000000")) + var hashBytes = MD5.HashData(Encoding.ASCII.GetBytes(_key + counter)); + if (hashBytes[0] == 0 && hashBytes[1] == 0 && hashBytes[2] == 0) return counter; counter++; }