From 93786852a1f077c8ecd2a00362f7aed5f2494aaa Mon Sep 17 00:00:00 2001
From: LTRData
Date: Wed, 6 Mar 2024 11:01:01 +0100
Subject: [PATCH] Some encoding optimizations
---
Library/DiscUtils.Fat/FatFileSystem.cs | 4 +---
Library/DiscUtils.Ntfs/MasterFileTable.cs | 2 +-
Library/DiscUtils.Registry/KeyNodeCell.cs | 2 +-
Library/DiscUtils.Registry/SecurityCell.cs | 2 +-
Library/DiscUtils.Registry/ValueCell.cs | 2 +-
5 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/Library/DiscUtils.Fat/FatFileSystem.cs b/Library/DiscUtils.Fat/FatFileSystem.cs
index 9c05e9b16..cd2131011 100644
--- a/Library/DiscUtils.Fat/FatFileSystem.cs
+++ b/Library/DiscUtils.Fat/FatFileSystem.cs
@@ -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;
diff --git a/Library/DiscUtils.Ntfs/MasterFileTable.cs b/Library/DiscUtils.Ntfs/MasterFileTable.cs
index dec3f120c..8e05e9c8b 100644
--- a/Library/DiscUtils.Ntfs/MasterFileTable.cs
+++ b/Library/DiscUtils.Ntfs/MasterFileTable.cs
@@ -105,7 +105,7 @@ internal class MasterFileTable : IDiagnosticTraceable, IDisposable
///
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;
diff --git a/Library/DiscUtils.Registry/KeyNodeCell.cs b/Library/DiscUtils.Registry/KeyNodeCell.cs
index 7264d96d3..0fc1969be 100644
--- a/Library/DiscUtils.Registry/KeyNodeCell.cs
+++ b/Library/DiscUtils.Registry/KeyNodeCell.cs
@@ -106,7 +106,7 @@ public override void WriteTo(Span 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));
diff --git a/Library/DiscUtils.Registry/SecurityCell.cs b/Library/DiscUtils.Registry/SecurityCell.cs
index a2d67559e..28fa25a59 100644
--- a/Library/DiscUtils.Registry/SecurityCell.cs
+++ b/Library/DiscUtils.Registry/SecurityCell.cs
@@ -76,7 +76,7 @@ public override void WriteTo(Span 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));
diff --git a/Library/DiscUtils.Registry/ValueCell.cs b/Library/DiscUtils.Registry/ValueCell.cs
index 32c82c9e2..2805c4c07 100644
--- a/Library/DiscUtils.Registry/ValueCell.cs
+++ b/Library/DiscUtils.Registry/ValueCell.cs
@@ -89,7 +89,7 @@ public override void WriteTo(Span 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));