Skip to content

Commit

Permalink
Moved stackalloc outside loop
Browse files Browse the repository at this point in the history
  • Loading branch information
LTRData committed Apr 4, 2024
1 parent 8aba74b commit e7a535f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Library/DiscUtils.Lvm/MetadataLogicalVolumeSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ internal class MetadataLogicalVolumeSection

internal void Parse(string head, TextReader data)
{
Span<byte> guidBuffer = stackalloc byte[16];
var segments = new List<MetadataSegmentSection>();
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());
Expand All @@ -61,16 +62,14 @@ internal void Parse(string head, TextReader data)
case "id":
Id = Metadata.ParseStringValue(parameter.Value.Span);

Span<byte> 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>(guid);
guidBuffer[7] = (byte)((guidBuffer[7] | 0x40) & 0x4f);
guidBuffer[8] = (byte)((guidBuffer[8] | 0x80) & 0xbf);
Identity = MemoryMarshal.Read<Guid>(guidBuffer);
break;
case "status":
var values = Metadata.ParseArrayValue(parameter.Value.Span);
Expand Down

0 comments on commit e7a535f

Please sign in to comment.