Skip to content

Commit

Permalink
Some encoding optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
LTRData committed Mar 6, 2024
1 parent 8a54280 commit 9378685
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 7 deletions.
4 changes: 1 addition & 3 deletions Library/DiscUtils.Fat/FatFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,9 +1498,7 @@ private static void WriteBPB(
bootSector[2] = 0x90;

// OEM Name
EncodingUtilities
.GetLatin1Encoding()
.GetBytes("DISCUTIL", bootSector.Slice(3, 8));
"DISCUTIL"u8.CopyTo(bootSector.Slice(3, 8));

// Bytes Per Sector (512)
bootSector[11] = 0;
Expand Down
2 changes: 1 addition & 1 deletion Library/DiscUtils.Ntfs/MasterFileTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ internal class MasterFileTable : IDiagnosticTraceable, IDisposable
/// </summary>
private const uint FirstAvailableMftIndex = 24;

private static readonly int FILE_MAGIC = EndianUtilities.ToInt32LittleEndian(Encoding.ASCII.GetBytes("FILE"), 0);
private static readonly int FILE_MAGIC = EndianUtilities.ToInt32LittleEndian("FILE"u8);

private Bitmap _bitmap;
private int _bytesPerSector;
Expand Down
2 changes: 1 addition & 1 deletion Library/DiscUtils.Registry/KeyNodeCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public override void WriteTo(Span<byte> buffer)
{
var latin1Encoding = EncodingUtilities.GetLatin1Encoding();

latin1Encoding.GetBytes("nk", buffer.Slice(0, 2));
"nk"u8.CopyTo(buffer.Slice(0, 2));
EndianUtilities.WriteBytesLittleEndian((ushort)Flags, buffer.Slice(0x02));
EndianUtilities.WriteBytesLittleEndian(Timestamp.ToFileTimeUtc(), buffer.Slice(0x04));
EndianUtilities.WriteBytesLittleEndian(ParentIndex, buffer.Slice(0x10));
Expand Down
2 changes: 1 addition & 1 deletion Library/DiscUtils.Registry/SecurityCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override void WriteTo(Span<byte> buffer)
var latin1Encoding = EncodingUtilities.GetLatin1Encoding();
var sd = SecurityDescriptor.GetSecurityDescriptorBinaryForm();

latin1Encoding.GetBytes("sk", buffer.Slice(0, 2));
"sk"u8.CopyTo(buffer.Slice(0, 2));
EndianUtilities.WriteBytesLittleEndian(PreviousIndex, buffer.Slice(0x04));
EndianUtilities.WriteBytesLittleEndian(NextIndex, buffer.Slice(0x08));
EndianUtilities.WriteBytesLittleEndian(UsageCount, buffer.Slice(0x0C));
Expand Down
2 changes: 1 addition & 1 deletion Library/DiscUtils.Registry/ValueCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override void WriteTo(Span<byte> buffer)

var latin1Encoding = EncodingUtilities.GetLatin1Encoding();

latin1Encoding.GetBytes("vk", buffer.Slice(0, 2));
"vk"u8.CopyTo(buffer.Slice(0, 2));
EndianUtilities.WriteBytesLittleEndian(nameLen, buffer.Slice(0x02));
EndianUtilities.WriteBytesLittleEndian(DataLength, buffer.Slice(0x04));
EndianUtilities.WriteBytesLittleEndian(DataIndex, buffer.Slice(0x08));
Expand Down

0 comments on commit 9378685

Please sign in to comment.