From e7a535f896cd27bd7947cfefe4271e5ce9c4d7ca Mon Sep 17 00:00:00 2001 From: LTRData Date: Fri, 5 Apr 2024 01:52:21 +0200 Subject: [PATCH] Moved stackalloc outside loop --- .../DiscUtils.Lvm/MetadataLogicalVolumeSection.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Library/DiscUtils.Lvm/MetadataLogicalVolumeSection.cs b/Library/DiscUtils.Lvm/MetadataLogicalVolumeSection.cs index b0a19b33a..c58bce982 100644 --- a/Library/DiscUtils.Lvm/MetadataLogicalVolumeSection.cs +++ b/Library/DiscUtils.Lvm/MetadataLogicalVolumeSection.cs @@ -46,13 +46,14 @@ internal class MetadataLogicalVolumeSection internal void Parse(string head, TextReader data) { + Span guidBuffer = stackalloc byte[16]; var segments = new List(); Name = head.AsSpan().Trim().TrimEnd('{').TrimEnd().ToString(); string line; while ((line = Metadata.ReadLine(data)) != null) { - if (line == String.Empty) continue; + if (line == "") continue; if (line.AsSpan().Contains("=".AsSpan(), StringComparison.Ordinal)) { var parameter = Metadata.ParseParameter(line.AsMemory()); @@ -61,16 +62,14 @@ internal void Parse(string head, TextReader data) case "id": Id = Metadata.ParseStringValue(parameter.Value.Span); - Span guid = stackalloc byte[16]; - EncodingUtilities .GetLatin1Encoding() - .GetBytes(Id.Replace("-", String.Empty).AsSpan(0, 16), guid); + .GetBytes(Id.Replace("-", "").AsSpan(0, 16), guidBuffer); // Mark it as a version 4 GUID - guid[7] = (byte)((guid[7] | 0x40) & 0x4f); - guid[8] = (byte)((guid[8] | 0x80) & 0xbf); - Identity = MemoryMarshal.Read(guid); + guidBuffer[7] = (byte)((guidBuffer[7] | 0x40) & 0x4f); + guidBuffer[8] = (byte)((guidBuffer[8] | 0x80) & 0xbf); + Identity = MemoryMarshal.Read(guidBuffer); break; case "status": var values = Metadata.ParseArrayValue(parameter.Value.Span);